Skip to content

Commit f464f22

Browse files
committed
History access in Webview update.
Webview now has: -getPagesHistory function, returning array of URLs, titles and favicons of pages in history. Titles and favicons are not known for current page because array is created before page is fully loaded. -getCurrentHistoryIndex function, returning current history index
1 parent 7638a43 commit f464f22

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

extensions/browser/guest_view/web_view/web_view_guest.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "content/public/browser/browser_context.h"
2727
#include "content/public/browser/browser_thread.h"
2828
#include "content/public/browser/child_process_security_policy.h"
29+
#include "content/public/browser/favicon_status.h"
2930
#include "content/public/browser/native_web_keyboard_event.h"
3031
#include "content/public/browser/navigation_entry.h"
3132
#include "content/public/browser/navigation_handle.h"
@@ -859,6 +860,16 @@ void WebViewGuest::DidFinishNavigation(
859860
web_contents()->GetController().GetCurrentEntryIndex());
860861
args->SetInteger(webview::kInternalEntryCount,
861862
web_contents()->GetController().GetEntryCount());
863+
864+
base::ListValue *history = new base::ListValue();
865+
for (int i = 0; i < web_contents()->GetController().GetEntryCount(); i++) {
866+
base::DictionaryValue* dict = new base::DictionaryValue;
867+
dict->SetString("url", web_contents()->GetController().GetEntryAtIndex(i)->GetURL().spec());
868+
dict->SetString("title", web_contents()->GetController().GetEntryAtIndex(i)->GetTitle());
869+
dict->SetString("favicon", web_contents()->GetController().GetEntryAtIndex(i)->GetFavicon().url.spec());
870+
history->Append(dict);
871+
}
872+
args->Set("pagesHistory", history);
862873
args->SetInteger(webview::kInternalProcessId,
863874
web_contents()->GetRenderProcessHost()->GetID());
864875
DispatchEventToView(base::MakeUnique<GuestViewEvent>(

extensions/renderer/resources/guest_view/web_view/web_view.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,12 @@ WebViewImpl.prototype.onFrameNameChanged = function(name) {
148148
// Updates state upon loadcommit.
149149
WebViewImpl.prototype.onLoadCommit = function(
150150
baseUrlForDataUrl, currentEntryIndex, entryCount,
151-
processId, url, isTopLevel) {
151+
processId, url, isTopLevel, pagesHistory) {
152152
this.baseUrlForDataUrl = baseUrlForDataUrl;
153153
this.currentEntryIndex = currentEntryIndex;
154154
this.entryCount = entryCount;
155155
this.processId = processId;
156+
this.pagesHistory = pagesHistory;
156157
if (isTopLevel) {
157158
// Touching the src attribute triggers a navigation. To avoid
158159
// triggering a page reload on every guest-initiated navigation,

extensions/renderer/resources/guest_view/web_view/web_view_api_methods.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ var WEB_VIEW_API_METHODS = [
5252
// Navigates to the subsequent history entry.
5353
'forward',
5454

55+
// Get current history index
56+
'getCurrentHistoryIndex',
57+
58+
// Get array with history of URLs titles and favicons
59+
'getPagesHistory',
60+
5561
// Returns Chrome's internal process ID for the guest web page's current
5662
// process.
5763
'getProcessId',
@@ -82,6 +88,7 @@ var WEB_VIEW_API_METHODS = [
8288
'loadDataWithBaseUrl',
8389

8490
'showDevTools',
91+
8592
// Prints the contents of the webview.
8693
'print',
8794

@@ -151,6 +158,14 @@ WebViewImpl.prototype.getUserAgent = function() {
151158
return this.userAgentOverride || navigator.userAgent;
152159
};
153160

161+
WebViewImpl.prototype.getCurrentHistoryIndex = function () {
162+
return this.currentEntryIndex;
163+
};
164+
165+
WebViewImpl.prototype.getPagesHistory = function() {
166+
return this.pagesHistory;
167+
};
168+
154169
WebViewImpl.prototype.insertCSS = function(var_args) {
155170
return this.executeCode(WebViewInternal.insertCSS, $Array.slice(arguments));
156171
};

extensions/renderer/resources/guest_view/web_view/web_view_events.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ WebViewEvents.prototype.handleLoadCommitEvent = function(event, eventName) {
249249
event.entryCount,
250250
event.processId,
251251
event.url,
252-
event.isTopLevel);
252+
event.isTopLevel,
253+
event.pagesHistory);
253254
var webViewEvent = this.makeDomEvent(event, eventName);
254255
this.view.dispatchEvent(webViewEvent);
255256
};

0 commit comments

Comments
 (0)