diff --git a/chrome/browser/extensions/api/history/history_api.cc b/chrome/browser/extensions/api/history/history_api.cc index 9d0441493caa1..8db7f35c620e0 100644 --- a/chrome/browser/extensions/api/history/history_api.cc +++ b/chrome/browser/extensions/api/history/history_api.cc @@ -351,10 +351,17 @@ bool HistoryAddUrlFunction::RunAsync() { if (!ValidateUrl(params->details.url, &url)) return false; + base::string16 title; + if (params->details.title.get()) + title = base::UTF8ToUTF16(*params->details.title); + history::HistoryService* hs = HistoryServiceFactory::GetForProfile( GetProfile(), ServiceAccessType::EXPLICIT_ACCESS); hs->AddPage(url, base::Time::Now(), history::SOURCE_EXTENSION); + if (!title.empty()) + hs->SetPageTitle(url, title); + SendResponse(true); return true; } diff --git a/chrome/common/extensions/api/history.json b/chrome/common/extensions/api/history.json index 2eb7044ad3b7f..994aefd5b01ee 100644 --- a/chrome/common/extensions/api/history.json +++ b/chrome/common/extensions/api/history.json @@ -97,7 +97,8 @@ "name": "details", "type": "object", "properties": { - "url": {"type": "string", "description": "The URL to add."} + "url": {"type": "string", "description": "The URL to add."}, + "title": {"type": "string", "optional": true, "description": "The title of URL to add."} } }, { diff --git a/extensions/browser/guest_view/web_view/web_view_guest.cc b/extensions/browser/guest_view/web_view/web_view_guest.cc index d142c1bc57f62..b846b4b6e0093 100644 --- a/extensions/browser/guest_view/web_view/web_view_guest.cc +++ b/extensions/browser/guest_view/web_view/web_view_guest.cc @@ -26,6 +26,7 @@ #include "content/public/browser/browser_context.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/child_process_security_policy.h" +#include "content/public/browser/favicon_status.h" #include "content/public/browser/native_web_keyboard_event.h" #include "content/public/browser/navigation_entry.h" #include "content/public/browser/notification_details.h" @@ -842,6 +843,16 @@ void WebViewGuest::DidCommitProvisionalLoadForFrame( web_contents()->GetController().GetCurrentEntryIndex()); args->SetInteger(webview::kInternalEntryCount, web_contents()->GetController().GetEntryCount()); + + base::ListValue *history = new base::ListValue(); + for (int i = 0; i < web_contents()->GetController().GetEntryCount(); i++) { + base::DictionaryValue* dict = new base::DictionaryValue; + dict->SetString("url", web_contents()->GetController().GetEntryAtIndex(i)->GetURL().spec()); + dict->SetString("title", web_contents()->GetController().GetEntryAtIndex(i)->GetTitle()); + dict->SetString("favicon", web_contents()->GetController().GetEntryAtIndex(i)->GetFavicon().url.spec()); + history->Append(dict); + } + args->Set("pagesHistory", history); args->SetInteger(webview::kInternalProcessId, web_contents()->GetRenderProcessHost()->GetID()); DispatchEventToView(base::MakeUnique( diff --git a/extensions/renderer/resources/guest_view/web_view/web_view.js b/extensions/renderer/resources/guest_view/web_view/web_view.js index 6dd4faeb9c042..51fee1c7d246c 100644 --- a/extensions/renderer/resources/guest_view/web_view/web_view.js +++ b/extensions/renderer/resources/guest_view/web_view/web_view.js @@ -148,11 +148,12 @@ WebViewImpl.prototype.onFrameNameChanged = function(name) { // Updates state upon loadcommit. WebViewImpl.prototype.onLoadCommit = function( baseUrlForDataUrl, currentEntryIndex, entryCount, - processId, url, isTopLevel) { + processId, url, isTopLevel, pagesHistory) { this.baseUrlForDataUrl = baseUrlForDataUrl; this.currentEntryIndex = currentEntryIndex; this.entryCount = entryCount; this.processId = processId; + this.pagesHistory = pagesHistory; if (isTopLevel) { // Touching the src attribute triggers a navigation. To avoid // triggering a page reload on every guest-initiated navigation, diff --git a/extensions/renderer/resources/guest_view/web_view/web_view_api_methods.js b/extensions/renderer/resources/guest_view/web_view/web_view_api_methods.js index faba4e84462f9..35d1336d4a23c 100644 --- a/extensions/renderer/resources/guest_view/web_view/web_view_api_methods.js +++ b/extensions/renderer/resources/guest_view/web_view/web_view_api_methods.js @@ -52,6 +52,12 @@ var WEB_VIEW_API_METHODS = [ // Navigates to the subsequent history entry. 'forward', + // Get current history index + 'getCurrentHistoryIndex', + + // Get array with history of URLs titles and favicons + 'getPagesHistory', + // Returns Chrome's internal process ID for the guest web page's current // process. 'getProcessId', @@ -82,6 +88,7 @@ var WEB_VIEW_API_METHODS = [ 'loadDataWithBaseUrl', 'showDevTools', + // Prints the contents of the webview. 'print', @@ -151,6 +158,14 @@ WebViewImpl.prototype.getUserAgent = function() { return this.userAgentOverride || navigator.userAgent; }; +WebViewImpl.prototype.getCurrentHistoryIndex = function () { + return this.currentEntryIndex; +}; + +WebViewImpl.prototype.getPagesHistory = function() { + return this.pagesHistory; +}; + WebViewImpl.prototype.insertCSS = function(var_args) { return this.executeCode(WebViewInternal.insertCSS, $Array.slice(arguments)); }; diff --git a/extensions/renderer/resources/guest_view/web_view/web_view_events.js b/extensions/renderer/resources/guest_view/web_view/web_view_events.js index 1077684de0038..a9318549067df 100644 --- a/extensions/renderer/resources/guest_view/web_view/web_view_events.js +++ b/extensions/renderer/resources/guest_view/web_view/web_view_events.js @@ -249,7 +249,8 @@ WebViewEvents.prototype.handleLoadCommitEvent = function(event, eventName) { event.entryCount, event.processId, event.url, - event.isTopLevel); + event.isTopLevel, + event.pagesHistory); var webViewEvent = this.makeDomEvent(event, eventName); this.view.dispatchEvent(webViewEvent); };