Skip to content

Improve working with history #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions chrome/browser/extensions/api/history/history_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion chrome/common/extensions/api/history.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."}
}
},
{
Expand Down
11 changes: 11 additions & 0 deletions extensions/browser/guest_view/web_view/web_view_guest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<GuestViewEvent>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -82,6 +88,7 @@ var WEB_VIEW_API_METHODS = [
'loadDataWithBaseUrl',

'showDevTools',

// Prints the contents of the webview.
'print',

Expand Down Expand Up @@ -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));
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand Down