summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-12 03:55:56 +0000
committerdhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-12 03:55:56 +0000
commite7868c8893fa2d2a9ed3e112fcd2fca5ffb8e30c (patch)
tree9aeb89adc7211fb3fd0134557685068856b3d4f3
parent68852bdf95b0a8a4d7dfc70578caa503f49f3dbf (diff)
downloadchromium_src-e7868c8893fa2d2a9ed3e112fcd2fca5ffb8e30c.zip
chromium_src-e7868c8893fa2d2a9ed3e112fcd2fca5ffb8e30c.tar.gz
chromium_src-e7868c8893fa2d2a9ed3e112fcd2fca5ffb8e30c.tar.bz2
Most visited thumbnails and favicons need id-based urls
Extends ThumbnailSouce and FaviconSource to serve requests of the form: chrome-search://favicon/<id> chrome-search://thumb/<id> BUG=180371 TEST=Manual, look at NTP Most Visited on 1993 R=sreeram@chromium.org Review URL: https://codereview.chromium.org/12732005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@187480 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/instant/instant_controller.cc42
-rw-r--r--chrome/browser/instant/instant_controller.h6
-rw-r--r--chrome/browser/instant/instant_io_context.cc65
-rw-r--r--chrome/browser/instant/instant_io_context.h29
-rw-r--r--chrome/browser/instant/instant_page.cc18
-rw-r--r--chrome/browser/instant/instant_page.h10
-rw-r--r--chrome/browser/instant/instant_service.cc173
-rw-r--r--chrome/browser/instant/instant_service.h45
-rw-r--r--chrome/browser/ui/webui/favicon_source.cc18
-rw-r--r--chrome/browser/ui/webui/ntp/thumbnail_source.cc28
-rw-r--r--chrome/browser/ui/webui/ntp/thumbnail_source.h7
-rw-r--r--chrome/common/instant_types.h13
-rw-r--r--chrome/common/render_messages.h17
-rw-r--r--chrome/renderer/resources/extensions/searchbox_api.js8
-rw-r--r--chrome/renderer/searchbox/searchbox.cc66
-rw-r--r--chrome/renderer/searchbox/searchbox.h29
-rw-r--r--chrome/renderer/searchbox/searchbox_extension.cc69
17 files changed, 485 insertions, 158 deletions
diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc
index 0adef54..0d736b6 100644
--- a/chrome/browser/instant/instant_controller.cc
+++ b/chrome/browser/instant/instant_controller.cc
@@ -15,6 +15,7 @@
#include "chrome/browser/history/top_sites.h"
#include "chrome/browser/instant/instant_ntp.h"
#include "chrome/browser/instant/instant_overlay.h"
+#include "chrome/browser/instant/instant_service.h"
#include "chrome/browser/instant/instant_service_factory.h"
#include "chrome/browser/instant/instant_tab.h"
#include "chrome/browser/instant/search.h"
@@ -196,6 +197,25 @@ void EnsureSearchTermsAreSet(content::WebContents* contents,
NavigationEntryUpdated();
}
+bool GetURLForMostVisitedItemId(Profile* profile,
+ uint64 most_visited_item_id,
+ GURL* url) {
+ InstantService* instant_service =
+ InstantServiceFactory::GetForProfile(profile);
+ if (!instant_service)
+ return false;
+ return instant_service->GetURLForMostVisitedItemId(most_visited_item_id, url);
+}
+
+// Creates a new restriced id if one is not found.
+size_t GetMostVisitedItemIDForURL(Profile* profile, const GURL& url) {
+ InstantService* instant_service =
+ InstantServiceFactory::GetForProfile(profile);
+ if (!instant_service)
+ return 0;
+ return instant_service->AddURL(url);
+}
+
} // namespace
InstantController::InstantController(chrome::BrowserInstantController* browser,
@@ -869,20 +889,26 @@ void InstantController::ClearDebugEvents() {
debug_events_.clear();
}
-void InstantController::DeleteMostVisitedItem(const GURL& url) {
+void InstantController::DeleteMostVisitedItem(uint64 most_visited_item_id) {
history::TopSites* top_sites = browser_->profile()->GetTopSites();
if (!top_sites)
return;
- top_sites->AddBlacklistedURL(url);
+ GURL url;
+ if (GetURLForMostVisitedItemId(browser_->profile(),
+ most_visited_item_id, &url))
+ top_sites->AddBlacklistedURL(url);
}
-void InstantController::UndoMostVisitedDeletion(const GURL& url) {
+void InstantController::UndoMostVisitedDeletion(uint64 most_visited_item_id) {
history::TopSites* top_sites = browser_->profile()->GetTopSites();
if (!top_sites)
return;
- top_sites->RemoveBlacklistedURL(url);
+ GURL url;
+ if (GetURLForMostVisitedItemId(browser_->profile(),
+ most_visited_item_id, &url))
+ top_sites->RemoveBlacklistedURL(url);
}
void InstantController::UndoAllMostVisitedDeletions() {
@@ -1469,11 +1495,13 @@ void InstantController::RequestMostVisitedItems() {
void InstantController::OnMostVisitedItemsReceived(
const history::MostVisitedURLList& data) {
- std::vector<MostVisitedItem> most_visited_items;
+ std::vector<InstantMostVisitedItem> most_visited_items;
for (size_t i = 0; i < data.size(); i++) {
const history::MostVisitedURL& url = data[i];
- MostVisitedItem item;
+ InstantMostVisitedItem item;
+ item.most_visited_item_id = GetMostVisitedItemIDForURL(browser_->profile(),
+ url.url);
item.url = url.url;
item.title = url.title;
@@ -1483,7 +1511,7 @@ void InstantController::OnMostVisitedItemsReceived(
}
void InstantController::SendMostVisitedItems(
- const std::vector<MostVisitedItem>& items) {
+ const std::vector<InstantMostVisitedItem>& items) {
if (overlay_)
overlay_->SendMostVisitedItems(items);
if (ntp_)
diff --git a/chrome/browser/instant/instant_controller.h b/chrome/browser/instant/instant_controller.h
index 64a9b06..cca84ff0 100644
--- a/chrome/browser/instant/instant_controller.h
+++ b/chrome/browser/instant/instant_controller.h
@@ -249,11 +249,11 @@ class InstantController : public InstantPage::Delegate,
// Invoked by the InstantLoader when the Instant page wants to delete a
// Most Visited item.
- virtual void DeleteMostVisitedItem(const GURL& url) OVERRIDE;
+ virtual void DeleteMostVisitedItem(uint64 most_visited_item_id) OVERRIDE;
// Invoked by the InstantLoader when the Instant page wants to undo a
// Most Visited deletion.
- virtual void UndoMostVisitedDeletion(const GURL& url) OVERRIDE;
+ virtual void UndoMostVisitedDeletion(uint64 most_visited_item_id) OVERRIDE;
// Invoked by the InstantLoader when the Instant page wants to undo all
// Most Visited deletions.
@@ -347,7 +347,7 @@ class InstantController : public InstantPage::Delegate,
// Sends a collection of MostVisitedItems to the renderer process via
// the appropriate InstantPage subclass.
- void SendMostVisitedItems(const std::vector<MostVisitedItem>& items);
+ void SendMostVisitedItems(const std::vector<InstantMostVisitedItem>& items);
chrome::BrowserInstantController* const browser_;
diff --git a/chrome/browser/instant/instant_io_context.cc b/chrome/browser/instant/instant_io_context.cc
index a4ab4fd..e2199d6 100644
--- a/chrome/browser/instant/instant_io_context.cc
+++ b/chrome/browser/instant/instant_io_context.cc
@@ -7,6 +7,7 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/resource_context.h"
#include "content/public/browser/resource_request_info.h"
+#include "googleurl/src/gurl.h"
#include "net/url_request/url_request.h"
using content::BrowserThread;
@@ -21,6 +22,15 @@ InstantIOContext* GetDataForResourceContext(
context, InstantIOContext::kInstantIOContextKeyName);
}
+InstantIOContext* GetDataForRequest(const net::URLRequest* request) {
+ const content::ResourceRequestInfo* info =
+ content::ResourceRequestInfo::ForRequest(request);
+ if (!info)
+ return NULL;
+
+ return GetDataForResourceContext(info->GetContext());
+}
+
} // namespace
const char InstantIOContext::kInstantIOContextKeyName[] = "instant_io_context";
@@ -65,14 +75,38 @@ void InstantIOContext::ClearInstantProcessesOnIO(
}
// static
+void InstantIOContext::AddMostVisitedItemIDOnIO(
+ scoped_refptr<InstantIOContext> instant_io_context,
+ uint64 most_visited_item_id, const GURL& url) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ instant_io_context->most_visited_item_id_to_url_map_[most_visited_item_id] =
+ url;
+}
+
+// static
+void InstantIOContext::DeleteMostVisitedURLsOnIO(
+ scoped_refptr<InstantIOContext> instant_io_context,
+ std::vector<uint64> deleted_ids, bool all_history) {
+ if (all_history) {
+ instant_io_context->most_visited_item_id_to_url_map_.clear();
+ return;
+ }
+
+ for (size_t i = 0; i < deleted_ids.size(); ++i) {
+ instant_io_context->most_visited_item_id_to_url_map_.erase(
+ instant_io_context->most_visited_item_id_to_url_map_.find(
+ deleted_ids[i]));
+ }
+}
+
+// static
bool InstantIOContext::ShouldServiceRequest(const net::URLRequest* request) {
const content::ResourceRequestInfo* info =
content::ResourceRequestInfo::ForRequest(request);
if (!info)
return false;
- InstantIOContext* instant_io_context =
- GetDataForResourceContext(info->GetContext());
+ InstantIOContext* instant_io_context = GetDataForRequest(request);
if (!instant_io_context)
return false;
@@ -84,7 +118,34 @@ bool InstantIOContext::ShouldServiceRequest(const net::URLRequest* request) {
return false;
}
+// static
+bool InstantIOContext::GetURLForMostVisitedItemId(
+ const net::URLRequest* request,
+ uint64 most_visited_item_id,
+ GURL* url) {
+ InstantIOContext* instant_io_context = GetDataForRequest(request);
+ if (!instant_io_context) {
+ *url = GURL();
+ return false;
+ }
+
+ return instant_io_context->GetURLForMostVisitedItemId(most_visited_item_id,
+ url);
+}
+
bool InstantIOContext::IsInstantProcess(int process_id) const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
return process_ids_.count(process_id) != 0;
}
+
+bool InstantIOContext::GetURLForMostVisitedItemId(uint64 most_visited_item_id,
+ GURL* url) {
+ std::map<uint64, GURL>::iterator it =
+ most_visited_item_id_to_url_map_.find(most_visited_item_id);
+ if (it != most_visited_item_id_to_url_map_.end()) {
+ *url = it->second;
+ return true;
+ }
+ *url = GURL();
+ return false;
+}
diff --git a/chrome/browser/instant/instant_io_context.h b/chrome/browser/instant/instant_io_context.h
index 26b9a56..99b805c 100644
--- a/chrome/browser/instant/instant_io_context.h
+++ b/chrome/browser/instant/instant_io_context.h
@@ -5,11 +5,15 @@
#ifndef CHROME_BROWSER_INSTANT_INSTANT_IO_CONTEXT_
#define CHROME_BROWSER_INSTANT_INSTANT_IO_CONTEXT_
+#include <map>
#include <set>
+#include <vector>
#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
+class GURL;
+
namespace content {
class ResourceContext;
}
@@ -46,10 +50,28 @@ class InstantIOContext : public base::RefCountedThreadSafe<InstantIOContext> {
static void ClearInstantProcessesOnIO(
scoped_refptr<InstantIOContext> instant_io_context);
+ // Associates the |most_visited_item_id| with the |url|.
+ static void AddMostVisitedItemIDOnIO(
+ scoped_refptr<InstantIOContext> instant_io_context,
+ uint64 most_visited_item_id, const GURL& url);
+
+ // Deletes the Most Visited item IDs contained in |deleted_ids| from the url
+ // mapping. If |all_history| is true, then ignores |deleted_ids| and
+ // deletes all mappings.
+ static void DeleteMostVisitedURLsOnIO(
+ scoped_refptr<InstantIOContext> instant_io_context,
+ std::vector<uint64> deleted_ids, bool all_history);
+
// Determine if this chrome-search: request is coming from an Instant render
// process.
static bool ShouldServiceRequest(const net::URLRequest* request);
+ // Returns true if the |most_visited_item_id| is known, and |url| is set.
+ // Returns false otherwise.
+ static bool GetURLForMostVisitedItemId(
+ const net::URLRequest* request,
+ uint64 most_visited_item_id, GURL* url);
+
protected:
virtual ~InstantIOContext();
@@ -60,11 +82,18 @@ class InstantIOContext : public base::RefCountedThreadSafe<InstantIOContext> {
// |process_ids_|.
bool IsInstantProcess(int process_id) const;
+ bool GetURLForMostVisitedItemId(uint64 most_visited_item_id, GURL* url);
+
// The process IDs associated with Instant processes. Mirror of the process
// IDs in InstantService. Duplicated here for synchronous access on the IO
// thread.
std::set<int> process_ids_;
+ // The Most Visited item IDs map associated with Instant processes. Mirror of
+ // the Most Visited item ID map in InstantService. Duplicated here for
+ // synchronous access on the IO thread.
+ std::map<uint64, GURL> most_visited_item_id_to_url_map_;
+
DISALLOW_COPY_AND_ASSIGN(InstantIOContext);
};
diff --git a/chrome/browser/instant/instant_page.cc b/chrome/browser/instant/instant_page.cc
index 37496ee..c89521d 100644
--- a/chrome/browser/instant/instant_page.cc
+++ b/chrome/browser/instant/instant_page.cc
@@ -95,8 +95,8 @@ void InstantPage::KeyCaptureChanged(bool is_key_capture_enabled) {
}
void InstantPage::SendMostVisitedItems(
- const std::vector<MostVisitedItem>& items) {
- Send(new ChromeViewMsg_InstantMostVisitedItemsChanged(routing_id(), items));
+ const std::vector<InstantMostVisitedItem>& items) {
+ Send(new ChromeViewMsg_SearchBoxMostVisitedItemsChanged(routing_id(), items));
}
InstantPage::InstantPage(Delegate* delegate)
@@ -173,11 +173,11 @@ bool InstantPage::OnMessageReceived(const IPC::Message& message) {
OnStopCapturingKeyStrokes);
IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxNavigate,
OnSearchBoxNavigate);
- IPC_MESSAGE_HANDLER(ChromeViewHostMsg_InstantDeleteMostVisitedItem,
+ IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem,
OnDeleteMostVisitedItem);
- IPC_MESSAGE_HANDLER(ChromeViewHostMsg_InstantUndoMostVisitedDeletion,
+ IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion,
OnUndoMostVisitedDeletion);
- IPC_MESSAGE_HANDLER(ChromeViewHostMsg_InstantUndoAllMostVisitedDeletions,
+ IPC_MESSAGE_HANDLER(ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions,
OnUndoAllMostVisitedDeletions);
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
@@ -270,12 +270,12 @@ void InstantPage::OnSearchBoxNavigate(int page_id,
}
}
-void InstantPage::OnDeleteMostVisitedItem(const GURL& url) {
- delegate_->DeleteMostVisitedItem(url);
+void InstantPage::OnDeleteMostVisitedItem(uint64 most_visited_item_id) {
+ delegate_->DeleteMostVisitedItem(most_visited_item_id);
}
-void InstantPage::OnUndoMostVisitedDeletion(const GURL& url) {
- delegate_->UndoMostVisitedDeletion(url);
+void InstantPage::OnUndoMostVisitedDeletion(uint64 most_visited_item_id) {
+ delegate_->UndoMostVisitedDeletion(most_visited_item_id);
}
void InstantPage::OnUndoAllMostVisitedDeletions() {
diff --git a/chrome/browser/instant/instant_page.h b/chrome/browser/instant/instant_page.h
index 024d44b..15c8fe4 100644
--- a/chrome/browser/instant/instant_page.h
+++ b/chrome/browser/instant/instant_page.h
@@ -90,10 +90,10 @@ class InstantPage : public content::WebContentsObserver {
WindowOpenDisposition disposition) = 0;
// Called when the SearchBox wants to delete a Most Visited item.
- virtual void DeleteMostVisitedItem(const GURL& url) = 0;
+ virtual void DeleteMostVisitedItem(uint64 most_visited_item_id) = 0;
// Called when the SearchBox wants to undo a Most Visited deletion.
- virtual void UndoMostVisitedDeletion(const GURL& url) = 0;
+ virtual void UndoMostVisitedDeletion(uint64 most_visited_item_id) = 0;
// Called when the SearchBox wants to undo all Most Visited deletions.
virtual void UndoAllMostVisitedDeletions() = 0;
@@ -171,7 +171,7 @@ class InstantPage : public content::WebContentsObserver {
void KeyCaptureChanged(bool is_key_capture_enabled);
// Tells the page about new Most Visited data.
- void SendMostVisitedItems(const std::vector<MostVisitedItem>& items);
+ void SendMostVisitedItems(const std::vector<InstantMostVisitedItem>& items);
protected:
explicit InstantPage(Delegate* delegate);
@@ -228,8 +228,8 @@ class InstantPage : public content::WebContentsObserver {
const GURL& url,
content::PageTransition transition,
WindowOpenDisposition disposition);
- void OnDeleteMostVisitedItem(const GURL& url);
- void OnUndoMostVisitedDeletion(const GURL& url);
+ void OnDeleteMostVisitedItem(uint64 most_visited_item_id);
+ void OnUndoMostVisitedDeletion(uint64 most_visited_item_id);
void OnUndoAllMostVisitedDeletions();
Delegate* const delegate_;
diff --git a/chrome/browser/instant/instant_service.cc b/chrome/browser/instant/instant_service.cc
index 3c8a6b2..9482a8f 100644
--- a/chrome/browser/instant/instant_service.cc
+++ b/chrome/browser/instant/instant_service.cc
@@ -4,7 +4,10 @@
#include "chrome/browser/instant/instant_service.h"
+#include "base/strings/string_number_conversions.h"
+#include "chrome/browser/history/history_notifications.h"
#include "chrome/browser/instant/instant_io_context.h"
+#include "chrome/browser/instant/instant_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/ntp/thumbnail_source.h"
#include "chrome/common/chrome_notification_types.h"
@@ -13,11 +16,29 @@
#include "content/public/browser/notification_types.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/url_data_source.h"
+#include "googleurl/src/gurl.h"
+#include "net/url_request/url_request.h"
using content::BrowserThread;
+namespace {
+
+// Copies deleted urls out of the history data structure |details| into a
+// straight vector of GURLs.
+void HistoryDetailsToDeletedURLs(const history::URLsDeletedDetails& details,
+ std::vector<GURL>* deleted_urls) {
+ for (history::URLRows::const_iterator it = details.rows.begin();
+ it != details.rows.end();
+ ++it) {
+ deleted_urls->push_back(it->url());
+ }
+}
+
+} // namespace
+
InstantService::InstantService(Profile* profile)
- : profile_(profile) {
+ : profile_(profile),
+ last_most_visited_item_id_(0) {
// Stub for unit tests.
if (!BrowserThread::CurrentlyOn(BrowserThread::UI))
return;
@@ -25,6 +46,9 @@ InstantService::InstantService(Profile* profile)
registrar_.Add(this,
content::NOTIFICATION_RENDERER_PROCESS_TERMINATED,
content::NotificationService::AllSources());
+ registrar_.Add(this,
+ chrome::NOTIFICATION_HISTORY_URLS_DELETED,
+ content::NotificationService::AllSources());
instant_io_context_ = new InstantIOContext();
@@ -41,6 +65,48 @@ InstantService::InstantService(Profile* profile)
InstantService::~InstantService() {
}
+// static
+const std::string InstantService::MaybeTranslateInstantPathOnUI(
+ Profile* profile, const std::string& path) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ InstantService* instant_service =
+ InstantServiceFactory::GetForProfile(profile);
+ if (!instant_service)
+ return path;
+
+ uint64 most_visited_item_id = 0;
+ if (base::StringToUint64(path, &most_visited_item_id)) {
+ GURL url;
+ if (instant_service->GetURLForMostVisitedItemId(most_visited_item_id, &url))
+ return url.spec();
+ }
+ return path;
+}
+
+const std::string InstantService::MaybeTranslateInstantPathOnIO(
+ const net::URLRequest* request, const std::string& path) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ uint64 most_visited_item_id = 0;
+ if (base::StringToUint64(path, &most_visited_item_id)) {
+ GURL url;
+ if (InstantIOContext::GetURLForMostVisitedItemId(request,
+ most_visited_item_id,
+ &url))
+ return url.spec();
+ }
+ return path;
+}
+
+// static
+bool InstantService::IsInstantPath(const GURL& url) {
+ // Strip leading slash.
+ std::string path = url.path().substr(1);
+
+ // Check that path is of Most Visited item ID form.
+ uint64 dummy = 0;
+ return base::StringToUint64(path, &dummy);
+}
+
void InstantService::AddInstantProcess(int process_id) {
process_ids_.insert(process_id);
@@ -56,6 +122,50 @@ bool InstantService::IsInstantProcess(int process_id) const {
return process_ids_.find(process_id) != process_ids_.end();
}
+uint64 InstantService::AddURL(const GURL& url) {
+ uint64 id = 0;
+ if (GetMostVisitedItemIDForURL(url, &id))
+ return id;
+
+ last_most_visited_item_id_++;
+ most_visited_item_id_to_url_map_[last_most_visited_item_id_] = url;
+ url_to_most_visited_item_id_map_[url] = last_most_visited_item_id_;
+
+ if (instant_io_context_) {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&InstantIOContext::AddMostVisitedItemIDOnIO,
+ instant_io_context_, last_most_visited_item_id_, url));
+ }
+
+ return last_most_visited_item_id_;
+}
+
+bool InstantService::GetMostVisitedItemIDForURL(
+ const GURL& url,
+ uint64 *most_visited_item_id) {
+ std::map<GURL, uint64>::iterator it =
+ url_to_most_visited_item_id_map_.find(url);
+ if (it != url_to_most_visited_item_id_map_.end()) {
+ *most_visited_item_id = it->second;
+ return true;
+ }
+ *most_visited_item_id = 0;
+ return false;
+}
+
+bool InstantService::GetURLForMostVisitedItemId(uint64 most_visited_item_id,
+ GURL* url) {
+ std::map<uint64, GURL>::iterator it =
+ most_visited_item_id_to_url_map_.find(most_visited_item_id);
+ if (it != most_visited_item_id_to_url_map_.end()) {
+ *url = it->second;
+ return true;
+ }
+ *url = GURL();
+ return false;
+}
+
void InstantService::Shutdown() {
process_ids_.clear();
@@ -71,14 +181,59 @@ void InstantService::Shutdown() {
void InstantService::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
- DCHECK_EQ(type, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED);
- int process_id = content::Source<content::RenderProcessHost>(source)->GetID();
- process_ids_.erase(process_id);
+ switch (type) {
+ case content::NOTIFICATION_RENDERER_PROCESS_TERMINATED: {
+ int process_id =
+ content::Source<content::RenderProcessHost>(source)->GetID();
+ process_ids_.erase(process_id);
+
+ if (instant_io_context_) {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&InstantIOContext::RemoveInstantProcessOnIO,
+ instant_io_context_, process_id));
+ }
+ break;
+ }
+ case chrome::NOTIFICATION_HISTORY_URLS_DELETED: {
+ content::Details<history::URLsDeletedDetails> det(details);
+ std::vector<GURL> deleted_urls;
+ HistoryDetailsToDeletedURLs(*det.ptr(), &deleted_urls);
+
+ std::vector<uint64> deleted_ids;
+ if (det->all_history) {
+ url_to_most_visited_item_id_map_.clear();
+ most_visited_item_id_to_url_map_.clear();
+ } else {
+ DeleteHistoryURLs(deleted_urls, &deleted_ids);
+ }
+
+ if (instant_io_context_) {
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&InstantIOContext::DeleteMostVisitedURLsOnIO,
+ instant_io_context_, deleted_ids, det->all_history));
+ }
+ break;
+ }
+ default:
+ NOTREACHED() << "Unexpected notification type in InstantService.";
+ }
+}
- if (instant_io_context_) {
- BrowserThread::PostTask(
- BrowserThread::IO, FROM_HERE,
- base::Bind(&InstantIOContext::RemoveInstantProcessOnIO,
- instant_io_context_, process_id));
+void InstantService::DeleteHistoryURLs(const std::vector<GURL>& deleted_urls,
+ std::vector<uint64>* deleted_ids) {
+ for (std::vector<GURL>::const_iterator it = deleted_urls.begin();
+ it != deleted_urls.end();
+ ++it) {
+ std::map<GURL, uint64>::iterator item =
+ url_to_most_visited_item_id_map_.find(*it);
+ if (item != url_to_most_visited_item_id_map_.end()) {
+ uint64 most_visited_item_id = item->second;
+ url_to_most_visited_item_id_map_.erase(item);
+ most_visited_item_id_to_url_map_.erase(
+ most_visited_item_id_to_url_map_.find(most_visited_item_id));
+ deleted_ids->push_back(most_visited_item_id);
+ }
}
}
diff --git a/chrome/browser/instant/instant_service.h b/chrome/browser/instant/instant_service.h
index 4e08d89..bdb8a35 100644
--- a/chrome/browser/instant/instant_service.h
+++ b/chrome/browser/instant/instant_service.h
@@ -5,7 +5,9 @@
#ifndef CHROME_BROWSER_INSTANT_INSTANT_SERVICE_H_
#define CHROME_BROWSER_INSTANT_INSTANT_SERVICE_H_
+#include <map>
#include <set>
+#include <string>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
@@ -14,9 +16,14 @@
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
+class GURL;
class InstantIOContext;
class Profile;
+namespace net {
+class URLRequest;
+}
+
// Tracks render process host IDs that are associated with Instant.
class InstantService : public ProfileKeyedService,
public content::NotificationObserver {
@@ -24,6 +31,19 @@ class InstantService : public ProfileKeyedService,
explicit InstantService(Profile* profile);
virtual ~InstantService();
+ // A utility to translate an Instant path if it is of Most Visited item ID
+ // form. If path is a Most Visited item ID and we have a URL for it, then
+ // this URL is returned in string form. The |path| is a URL fragment
+ // corresponding to the path of url with the leading slash ("/") stripped.
+ // For example, chrome-search://favicon/72 would yield a |path| value of "72",
+ // and since 72 is a valid uint64 the path is translated to a valid url,
+ // "http://bingo.com/", say.
+ static const std::string MaybeTranslateInstantPathOnUI(
+ Profile* profile, const std::string& path);
+ static const std::string MaybeTranslateInstantPathOnIO(
+ const net::URLRequest* request, const std::string& path);
+ static bool IsInstantPath(const GURL& url);
+
// Add, remove, and query RenderProcessHost IDs that are associated with
// Instant processes.
void AddInstantProcess(int process_id);
@@ -35,6 +55,19 @@ class InstantService : public ProfileKeyedService,
}
#endif
+ // If |url| is known the existing Most Visited item ID is returned. Otherwise
+ // a new Most Visited item ID is associated with the |url| and returned.
+ uint64 AddURL(const GURL& url);
+
+ // If there is a mapping for the |url|, sets |most_visited_item_id| and
+ // returns true.
+ bool GetMostVisitedItemIDForURL(const GURL& url,
+ uint64* most_visited_item_id);
+
+ // If there is a mapping for the |most_visited_item_id|, sets |url| and
+ // returns true.
+ bool GetURLForMostVisitedItemId(uint64 most_visited_item_id, GURL* url);
+
private:
// Overridden from ProfileKeyedService:
virtual void Shutdown() OVERRIDE;
@@ -44,11 +77,23 @@ class InstantService : public ProfileKeyedService,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
+ // Removes entries of each url in |deleted_urls| from the ID maps. Or all
+ // IDs if |all_history| is true. |deleted_ids| is filled with the newly
+ // deleted Most Visited item IDs.
+ void DeleteHistoryURLs(const std::vector<GURL>& deleted_urls,
+ std::vector<uint64>* deleted_ids);
+
Profile* const profile_;
// The process ids associated with Instant processes.
std::set<int> process_ids_;
+ // A mapping of Most Visited IDs to URLs. Used to hide Most Visited and
+ // Favicon URLs from the Instant search provider.
+ uint64 last_most_visited_item_id_;
+ std::map<uint64, GURL> most_visited_item_id_to_url_map_;
+ std::map<GURL, uint64> url_to_most_visited_item_id_map_;
+
content::NotificationRegistrar registrar_;
scoped_refptr<InstantIOContext> instant_io_context_;
diff --git a/chrome/browser/ui/webui/favicon_source.cc b/chrome/browser/ui/webui/favicon_source.cc
index 3c86582..7414c43 100644
--- a/chrome/browser/ui/webui/favicon_source.cc
+++ b/chrome/browser/ui/webui/favicon_source.cc
@@ -10,6 +10,8 @@
#include "chrome/browser/favicon/favicon_service_factory.h"
#include "chrome/browser/history/top_sites.h"
#include "chrome/browser/instant/instant_io_context.h"
+#include "chrome/browser/instant/instant_service.h"
+#include "chrome/browser/instant/instant_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/url_constants.h"
#include "grit/locale_settings.h"
@@ -80,16 +82,22 @@ std::string FaviconSource::GetSource() {
}
void FaviconSource::StartDataRequest(
- const std::string& path,
+ const std::string& raw_path,
bool is_incognito,
const content::URLDataSource::GotDataCallback& callback) {
FaviconService* favicon_service =
FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS);
- if (!favicon_service || path.empty()) {
+ if (!favicon_service || raw_path.empty()) {
SendDefaultResponse(callback);
return;
}
+ // Translate to regular path if |raw_path| is of the form
+ // chrome-search://favicon/<most_visited_item_id>, where
+ // "most_visited_item_id" is a uint64.
+ std::string path = InstantService::MaybeTranslateInstantPathOnUI(profile_,
+ raw_path);
+
DCHECK_EQ(16, gfx::kFaviconSize);
int size_in_dip = 16;
ui::ScaleFactor scale_factor = ui::SCALE_FACTOR_100P;
@@ -219,8 +227,10 @@ bool FaviconSource::ShouldReplaceExistingSource() const {
}
bool FaviconSource::ShouldServiceRequest(const net::URLRequest* request) const {
- if (request->url().SchemeIs(chrome::kChromeSearchScheme))
- return InstantIOContext::ShouldServiceRequest(request);
+ if (request->url().SchemeIs(chrome::kChromeSearchScheme)) {
+ return InstantService::IsInstantPath(request->url()) &&
+ InstantIOContext::ShouldServiceRequest(request);
+ }
return URLDataSource::ShouldServiceRequest(request);
}
diff --git a/chrome/browser/ui/webui/ntp/thumbnail_source.cc b/chrome/browser/ui/webui/ntp/thumbnail_source.cc
index 706b760..0848da3 100644
--- a/chrome/browser/ui/webui/ntp/thumbnail_source.cc
+++ b/chrome/browser/ui/webui/ntp/thumbnail_source.cc
@@ -8,6 +8,8 @@
#include "base/message_loop.h"
#include "base/memory/ref_counted_memory.h"
#include "chrome/browser/instant/instant_io_context.h"
+#include "chrome/browser/instant/instant_service.h"
+#include "chrome/browser/instant/instant_service_factory.h"
#include "chrome/browser/thumbnails/thumbnail_service.h"
#include "chrome/browser/thumbnails/thumbnail_service_factory.h"
#include "chrome/browser/profiles/profile.h"
@@ -17,9 +19,13 @@
#include "net/url_request/url_request.h"
#include "ui/base/resource/resource_bundle.h"
+using content::BrowserThread;
+
// Set ThumbnailService now as Profile isn't thread safe.
ThumbnailSource::ThumbnailSource(Profile* profile)
- : thumbnail_service_(ThumbnailServiceFactory::GetForProfile(profile)) {
+ : thumbnail_service_(ThumbnailServiceFactory::GetForProfile(profile)),
+ current_request_(NULL),
+ profile_(profile) {
}
ThumbnailSource::~ThumbnailSource() {
@@ -30,9 +36,19 @@ std::string ThumbnailSource::GetSource() {
}
void ThumbnailSource::StartDataRequest(
- const std::string& path,
+ const std::string& raw_path,
bool is_incognito,
const content::URLDataSource::GotDataCallback& callback) {
+ // Translate to regular path if |raw_path| is of the form
+ // chrome-search://favicon/<rid>, where rid is a uint64.
+ std::string path = raw_path;
+ if (BrowserThread::CurrentlyOn(BrowserThread::IO)) {
+ path = InstantService::MaybeTranslateInstantPathOnIO(
+ current_request_, raw_path);
+ } else if (BrowserThread::CurrentlyOn(BrowserThread::UI)) {
+ path = InstantService::MaybeTranslateInstantPathOnUI(profile_, raw_path);
+ }
+
scoped_refptr<base::RefCountedMemory> data;
if (thumbnail_service_->GetPageThumbnail(GURL(path), &data)) {
// We have the thumbnail.
@@ -40,6 +56,7 @@ void ThumbnailSource::StartDataRequest(
} else {
callback.Run(default_thumbnail_);
}
+ current_request_ = NULL;
}
std::string ThumbnailSource::GetMimeType(const std::string&) const {
@@ -57,7 +74,10 @@ MessageLoop* ThumbnailSource::MessageLoopForRequestPath(
bool ThumbnailSource::ShouldServiceRequest(
const net::URLRequest* request) const {
- if (request->url().SchemeIs(chrome::kChromeSearchScheme))
- return InstantIOContext::ShouldServiceRequest(request);
+ current_request_ = request;
+ if (request->url().SchemeIs(chrome::kChromeSearchScheme)) {
+ return InstantService::IsInstantPath(request->url()) &&
+ InstantIOContext::ShouldServiceRequest(request);
+ }
return URLDataSource::ShouldServiceRequest(request);
}
diff --git a/chrome/browser/ui/webui/ntp/thumbnail_source.h b/chrome/browser/ui/webui/ntp/thumbnail_source.h
index dc98851..cbd82fa 100644
--- a/chrome/browser/ui/webui/ntp/thumbnail_source.h
+++ b/chrome/browser/ui/webui/ntp/thumbnail_source.h
@@ -49,6 +49,13 @@ class ThumbnailSource : public content::URLDataSource {
// ThumbnailService.
scoped_refptr<thumbnails::ThumbnailService> thumbnail_service_;
+ // Transient copy of the request in play. Valid between
+ // ShouldServiceRequest() and StartDataRequest().
+ mutable const net::URLRequest* current_request_;
+
+ // Only used when servicing requests on the UI thread.
+ Profile* const profile_;
+
DISALLOW_COPY_AND_ASSIGN(ThumbnailSource);
};
diff --git a/chrome/common/instant_types.h b/chrome/common/instant_types.h
index a7e748b..ae371c9 100644
--- a/chrome/common/instant_types.h
+++ b/chrome/common/instant_types.h
@@ -152,12 +152,17 @@ struct ThemeBackgroundInfo {
uint16 image_height;
};
-// A most visited item.
-struct MostVisitedItem {
- // URL of the most visited page.
+struct InstantMostVisitedItem {
+ InstantMostVisitedItem() : most_visited_item_id(0) {}
+
+ // A private identifier used on the browser side when retrieving assets.
+ uint64 most_visited_item_id;
+
+ // The URL of the Most Visited item.
GURL url;
- // Title of the most visited page.
+ // The title of the Most Visited page. May be empty, in which case the |url|
+ // is used as the title.
string16 title;
};
diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h
index d7b4751..2e491af 100644
--- a/chrome/common/render_messages.h
+++ b/chrome/common/render_messages.h
@@ -167,7 +167,8 @@ IPC_STRUCT_TRAITS_BEGIN(InstantAutocompleteResult)
IPC_STRUCT_TRAITS_MEMBER(relevance)
IPC_STRUCT_TRAITS_END()
-IPC_STRUCT_TRAITS_BEGIN(MostVisitedItem)
+IPC_STRUCT_TRAITS_BEGIN(InstantMostVisitedItem)
+ IPC_STRUCT_TRAITS_MEMBER(most_visited_item_id)
IPC_STRUCT_TRAITS_MEMBER(url)
IPC_STRUCT_TRAITS_MEMBER(title)
IPC_STRUCT_TRAITS_END()
@@ -342,16 +343,16 @@ IPC_MESSAGE_ROUTED1(ChromeViewMsg_SearchBoxKeyCaptureChanged,
IPC_MESSAGE_ROUTED1(ChromeViewMsg_SearchBoxGrantChromeSearchAccessFromOrigin,
GURL /* origin_url */)
-IPC_MESSAGE_ROUTED1(ChromeViewMsg_InstantMostVisitedItemsChanged,
- std::vector<MostVisitedItem> /* items */)
+IPC_MESSAGE_ROUTED1(ChromeViewMsg_SearchBoxMostVisitedItemsChanged,
+ std::vector<InstantMostVisitedItem> /* items */)
-IPC_MESSAGE_ROUTED1(ChromeViewHostMsg_InstantDeleteMostVisitedItem,
- GURL /* url */)
+IPC_MESSAGE_ROUTED1(ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem,
+ uint64 /* most_visited_item_id */)
-IPC_MESSAGE_ROUTED1(ChromeViewHostMsg_InstantUndoMostVisitedDeletion,
- GURL /* url */)
+IPC_MESSAGE_ROUTED1(ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion,
+ uint64 /* most_visited_item_id */)
-IPC_MESSAGE_ROUTED0(ChromeViewHostMsg_InstantUndoAllMostVisitedDeletions)
+IPC_MESSAGE_ROUTED0(ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions)
// Toggles visual muting of the render view area. This is on when a constrained
// window is showing.
diff --git a/chrome/renderer/resources/extensions/searchbox_api.js b/chrome/renderer/resources/extensions/searchbox_api.js
index 466299e..24b2bc1 100644
--- a/chrome/renderer/resources/extensions/searchbox_api.js
+++ b/chrome/renderer/resources/extensions/searchbox_api.js
@@ -330,14 +330,14 @@ if (!chrome.embeddedSearch) {
this.__defineGetter__('mostVisited', GetMostVisitedItemsWrapper);
this.__defineGetter__('themeBackgroundInfo', GetThemeBackgroundInfo);
- this.deleteMostVisitedItem = function(restrictId) {
- DeleteMostVisitedItem(restrictId);
+ this.deleteMostVisitedItem = function(restrictedId) {
+ DeleteMostVisitedItem(restrictedId);
};
this.undoAllMostVisitedDeletions = function() {
UndoAllMostVisitedDeletions();
};
- this.undoMostVisitedDeletion = function(restrictId) {
- UndoMostVisitedDeletion(restrictId);
+ this.undoMostVisitedDeletion = function(restrictedId) {
+ UndoMostVisitedDeletion(restrictedId);
};
this.navigateContentWindow = function(destination, disposition) {
NavigateNewTabPage(destination, disposition);
diff --git a/chrome/renderer/searchbox/searchbox.cc b/chrome/renderer/searchbox/searchbox.cc
index 37bd898..83a9bd5 100644
--- a/chrome/renderer/searchbox/searchbox.cc
+++ b/chrome/renderer/searchbox/searchbox.cc
@@ -12,16 +12,6 @@
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityPolicy.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
-namespace {
-
-// Prefix for a thumbnail URL.
-const char kThumbnailUrlPrefix[] = "chrome-search://thumb/";
-
-// Prefix for a thumbnail URL.
-const char kFaviconUrlPrefix[] = "chrome-search://favicon/";
-
-}
-
SearchBox::SearchBox(content::RenderView* render_view)
: content::RenderViewObserver(render_view),
content::RenderViewObserverTracker<SearchBox>(render_view),
@@ -33,8 +23,7 @@ SearchBox::SearchBox(content::RenderView* render_view)
last_results_base_(0),
is_key_capture_enabled_(false),
display_instant_results_(false),
- omnibox_font_size_(0),
- last_most_visited_item_id_(0) {
+ omnibox_font_size_(0) {
}
SearchBox::~SearchBox() {
@@ -84,20 +73,19 @@ void SearchBox::NavigateToURL(const GURL& url,
url, transition, disposition));
}
-void SearchBox::DeleteMostVisitedItem(int most_visited_item_id) {
- string16 url = MostVisitedItemIDToURL(most_visited_item_id);
- render_view()->Send(new ChromeViewHostMsg_InstantDeleteMostVisitedItem(
- render_view()->GetRoutingID(), GURL(url)));
+void SearchBox::DeleteMostVisitedItem(uint64 most_visited_item_id) {
+ render_view()->Send(new ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem(
+ render_view()->GetRoutingID(), most_visited_item_id));
}
-void SearchBox::UndoMostVisitedDeletion(int most_visited_item_id) {
- string16 url = MostVisitedItemIDToURL(most_visited_item_id);
- render_view()->Send(new ChromeViewHostMsg_InstantUndoMostVisitedDeletion(
- render_view()->GetRoutingID(), GURL(url)));
+void SearchBox::UndoMostVisitedDeletion(uint64 most_visited_item_id) {
+ render_view()->Send(new ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion(
+ render_view()->GetRoutingID(), most_visited_item_id));
}
void SearchBox::UndoAllMostVisitedDeletions() {
- render_view()->Send(new ChromeViewHostMsg_InstantUndoAllMostVisitedDeletions(
+ render_view()->Send(
+ new ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions(
render_view()->GetRoutingID()));
}
@@ -164,7 +152,7 @@ bool SearchBox::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(
ChromeViewMsg_SearchBoxGrantChromeSearchAccessFromOrigin,
OnGrantChromeSearchAccessFromOrigin)
- IPC_MESSAGE_HANDLER(ChromeViewMsg_InstantMostVisitedItemsChanged,
+ IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxMostVisitedItemsChanged,
OnMostVisitedChanged)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
@@ -352,7 +340,7 @@ void SearchBox::Reset() {
}
void SearchBox::OnMostVisitedChanged(
- const std::vector<MostVisitedItem>& items) {
+ const std::vector<InstantMostVisitedItem>& items) {
most_visited_items_ = items;
if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
@@ -361,35 +349,7 @@ void SearchBox::OnMostVisitedChanged(
}
}
-const std::vector<MostVisitedItem>& SearchBox::GetMostVisitedItems() {
+const std::vector<InstantMostVisitedItem>&
+SearchBox::GetMostVisitedItems() const {
return most_visited_items_;
}
-
-int SearchBox::URLToMostVisitedItemID(string16 url) {
- if (url_to_most_visited_item_id_map_[url])
- return url_to_most_visited_item_id_map_[url];
-
- last_most_visited_item_id_++;
- url_to_most_visited_item_id_map_[url] = last_most_visited_item_id_;
- most_visited_item_id_to_url_map_[last_most_visited_item_id_] = url;
-
- return last_most_visited_item_id_;
-}
-
-string16 SearchBox::MostVisitedItemIDToURL(int most_visited_item_id) {
- return most_visited_item_id_to_url_map_[most_visited_item_id];
-}
-
-string16 SearchBox::GenerateThumbnailUrl(int most_visited_item_id) {
- std::ostringstream ostr;
- ostr << kThumbnailUrlPrefix << most_visited_item_id;
- GURL url = GURL(ostr.str());
- return UTF8ToUTF16(url.spec());
-}
-
-string16 SearchBox::GenerateFaviconUrl(int most_visited_item_id) {
- std::ostringstream ostr;
- ostr << kFaviconUrlPrefix << most_visited_item_id;
- GURL url = GURL(ostr.str());
- return UTF8ToUTF16(url.spec());
-}
diff --git a/chrome/renderer/searchbox/searchbox.h b/chrome/renderer/searchbox/searchbox.h
index 9adc991..1882729 100644
--- a/chrome/renderer/searchbox/searchbox.h
+++ b/chrome/renderer/searchbox/searchbox.h
@@ -49,13 +49,14 @@ class SearchBox : public content::RenderViewObserver,
content::PageTransition transition,
WindowOpenDisposition disposition);
- // Sends ChromeViewHostMsg_InstantDeleteMostVisitedItem to the browser.
- void DeleteMostVisitedItem(int most_visited_item_id);
+ // Sends ChromeViewHostMsg_SearchBoxDeleteMostVisitedItem to the browser.
+ void DeleteMostVisitedItem(uint64 most_visited_item_id);
- // Sends ChromeViewHostMsg_InstantUndoMostVisitedDeletion to the browser.
- void UndoMostVisitedDeletion(int most_visited_item_id);
+ // Sends ChromeViewHostMsg_SearchBoxUndoMostVisitedDeletion to the browser.
+ void UndoMostVisitedDeletion(uint64 most_visited_item_id);
- // Sends ChromeViewHostMsg_InstantUndoAllMostVisitedDeletions to the browser.
+ // Sends ChromeViewHostMsg_SearchBoxUndoAllMostVisitedDeletions to the
+ // browser.
void UndoAllMostVisitedDeletions();
const string16& query() const { return query_; }
@@ -82,13 +83,7 @@ class SearchBox : public content::RenderViewObserver,
const ThemeBackgroundInfo& GetThemeBackgroundInfo();
// Most Visited items.
- const std::vector<MostVisitedItem>& GetMostVisitedItems();
-
- // Secure Urls.
- int URLToMostVisitedItemID(const string16 url);
- string16 MostVisitedItemIDToURL(int most_visited_item_id);
- string16 GenerateThumbnailUrl(int most_visited_item_id);
- string16 GenerateFaviconUrl(int most_visited_item_id);
+ const std::vector<InstantMostVisitedItem>& GetMostVisitedItems() const;
private:
// Overridden from content::RenderViewObserver:
@@ -115,7 +110,7 @@ class SearchBox : public content::RenderViewObserver,
void OnFontInformationReceived(const string16& omnibox_font,
size_t omnibox_font_size);
void OnGrantChromeSearchAccessFromOrigin(const GURL& origin_url);
- void OnMostVisitedChanged(const std::vector<MostVisitedItem>& items);
+ void OnMostVisitedChanged(const std::vector<InstantMostVisitedItem>& items);
// Returns the current zoom factor of the render view or 1 on failure.
double GetZoom() const;
@@ -138,13 +133,7 @@ class SearchBox : public content::RenderViewObserver,
bool display_instant_results_;
string16 omnibox_font_;
size_t omnibox_font_size_;
- std::vector<MostVisitedItem> most_visited_items_;
-
- // TODO(dcblack): Unify this logic to work with both Most Visited and
- // history suggestions. http://crbug.com/175768
- std::map<string16, int> url_to_most_visited_item_id_map_;
- std::map<int, string16> most_visited_item_id_to_url_map_;
- int last_most_visited_item_id_;
+ std::vector<InstantMostVisitedItem> most_visited_items_;
DISALLOW_COPY_AND_ASSIGN(SearchBox);
};
diff --git a/chrome/renderer/searchbox/searchbox_extension.cc b/chrome/renderer/searchbox/searchbox_extension.cc
index f456af0..25c4e09 100644
--- a/chrome/renderer/searchbox/searchbox_extension.cc
+++ b/chrome/renderer/searchbox/searchbox_extension.cc
@@ -63,6 +63,28 @@ void Dispatch(WebKit::WebFrame* frame, const WebKit::WebString& script) {
frame->executeScript(WebKit::WebScriptSource(script));
}
+v8::Handle<v8::String> GenerateThumbnailURL(uint64 most_visited_item_id) {
+ return UTF8ToV8String(
+ StringPrintf("chrome-search://thumb/%s",
+ base::Uint64ToString(most_visited_item_id).c_str()));
+}
+
+v8::Handle<v8::String> GenerateFaviconURL(uint64 most_visited_item_id) {
+ return UTF8ToV8String(
+ StringPrintf("chrome-search://favicon/%s",
+ base::Uint64ToString(most_visited_item_id).c_str()));
+}
+
+const GURL MostVisitedItemIDToURL(
+ const std::vector<InstantMostVisitedItem>& most_visited_items,
+ uint64 most_visited_item_id) {
+ for (size_t i = 0; i < most_visited_items.size(); ++i) {
+ if (most_visited_items[i].most_visited_item_id == most_visited_item_id)
+ return most_visited_items[i].url;
+ }
+ return GURL();
+}
+
} // namespace
namespace extensions_v8 {
@@ -730,8 +752,9 @@ v8::Handle<v8::Value> SearchBoxExtensionWrapper::NavigateNewTabPage(
GURL destination_url;
content::PageTransition transition = content::PAGE_TRANSITION_TYPED;
if (args[0]->IsNumber()) {
- destination_url = GURL(SearchBox::Get(render_view)->MostVisitedItemIDToURL(
- args[0]->Uint32Value()));
+ destination_url = MostVisitedItemIDToURL(
+ SearchBox::Get(render_view)->GetMostVisitedItems(),
+ args[0]->Uint32Value());
} else {
destination_url = GURL(V8ValueToUTF16(args[0]));
}
@@ -931,20 +954,16 @@ v8::Handle<v8::Value> SearchBoxExtensionWrapper::ShowOverlay(
v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetMostVisitedItems(
const v8::Arguments& args) {
content::RenderView* render_view = GetRenderView();
- if (!render_view) return v8::Undefined();
-
+ if (!render_view)
+ return v8::Undefined();
DVLOG(1) << render_view << " GetMostVisitedItems";
- const std::vector<MostVisitedItem>& items =
- SearchBox::Get(render_view)->GetMostVisitedItems();
- v8::Handle<v8::Array> items_array = v8::Array::New(items.size());
- for (size_t i = 0; i < items.size(); ++i) {
-
- const string16 url = UTF8ToUTF16(items[i].url.spec());
- const string16 host = UTF8ToUTF16(items[i].url.host());
- int most_visited_item_id =
- SearchBox::Get(render_view)->URLToMostVisitedItemID(url);
+ const SearchBox* search_box = SearchBox::Get(render_view);
+ const std::vector<InstantMostVisitedItem>& instant_mv_items =
+ search_box->GetMostVisitedItems();
+ v8::Handle<v8::Array> v8_mv_items = v8::Array::New(instant_mv_items.size());
+ for (size_t i = 0; i < instant_mv_items.size(); ++i) {
// We set the "dir" attribute of the title, so that in RTL locales, a LTR
// title is rendered left-to-right and truncated from the right. For
// example, the title of http://msdn.microsoft.com/en-us/default.aspx is
@@ -957,33 +976,31 @@ v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetMostVisitedItems(
// title will be rendered as "!Yahoo" if its "dir" attribute is not set to
// "ltr".
std::string direction;
- if (base::i18n::StringContainsStrongRTLChars(items[i].title))
+ if (base::i18n::StringContainsStrongRTLChars(instant_mv_items[i].title))
direction = kRTLHtmlTextDirection;
else
direction = kLTRHtmlTextDirection;
- string16 title = items[i].title;
+ string16 title = instant_mv_items[i].title;
if (title.empty())
- title = url;
+ title = UTF8ToUTF16(instant_mv_items[i].url.spec());
v8::Handle<v8::Object> item = v8::Object::New();
item->Set(v8::String::New("rid"),
- v8::Int32::New(most_visited_item_id));
+ v8::Int32::New(instant_mv_items[i].most_visited_item_id));
item->Set(v8::String::New("thumbnailUrl"),
- UTF16ToV8String(SearchBox::Get(render_view)->
- GenerateThumbnailUrl(most_visited_item_id)));
+ GenerateThumbnailURL(instant_mv_items[i].most_visited_item_id));
item->Set(v8::String::New("faviconUrl"),
- UTF16ToV8String(SearchBox::Get(render_view)->
- GenerateFaviconUrl(most_visited_item_id)));
+ GenerateFaviconURL(instant_mv_items[i].most_visited_item_id));
item->Set(v8::String::New("title"),
UTF16ToV8String(title));
- item->Set(v8::String::New("domain"), UTF16ToV8String(host));
- item->Set(v8::String::New("direction"),
- UTF8ToV8String(direction));
+ item->Set(v8::String::New("domain"),
+ UTF8ToV8String(instant_mv_items[i].url.host()));
+ item->Set(v8::String::New("direction"), UTF8ToV8String(direction));
- items_array->Set(i, item);
+ v8_mv_items->Set(i, item);
}
- return items_array;
+ return v8_mv_items;
}
// static