Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1860)

Unified Diff: chrome/renderer/searchbox/searchbox.cc

Issue 12386019: Instant: Use only one hidden WebContents per profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/searchbox/searchbox.cc
diff --git a/chrome/renderer/searchbox/searchbox.cc b/chrome/renderer/searchbox/searchbox.cc
index 59163ee0739287a2d7528451536f5c4592cf0d3d..fa2e5b7927acb82c20cbd547c89e50414d3b55b3 100644
--- a/chrome/renderer/searchbox/searchbox.cc
+++ b/chrome/renderer/searchbox/searchbox.cc
@@ -4,107 +4,22 @@
#include "chrome/renderer/searchbox/searchbox.h"
-#include "base/utf_string_conversions.h"
-#include "chrome/common/render_messages.h"
-#include "chrome/common/url_constants.h"
+#include "chrome/common/instant_messages.h"
#include "chrome/renderer/searchbox/searchbox_extension.h"
#include "content/public/renderer/render_view.h"
-#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),
verbatim_(false),
selection_start_(0),
- selection_end_(0),
- results_base_(0),
- start_margin_(0),
- last_results_base_(0),
- is_key_capture_enabled_(false),
- display_instant_results_(false),
- omnibox_font_size_(0),
- last_restricted_id_(0) {
+ selection_end_(0) {
}
SearchBox::~SearchBox() {
}
-void SearchBox::SetSuggestions(
- const std::vector<InstantSuggestion>& suggestions) {
- if (!suggestions.empty() &&
- suggestions[0].behavior == INSTANT_COMPLETE_REPLACE) {
- query_ = suggestions[0].text;
- verbatim_ = true;
- selection_start_ = selection_end_ = query_.size();
- }
- // Explicitly allow empty vector to be sent to the browser.
- render_view()->Send(new ChromeViewHostMsg_SetSuggestions(
- render_view()->GetRoutingID(), render_view()->GetPageId(), suggestions));
-}
-
-void SearchBox::ShowInstantOverlay(InstantShownReason reason,
- int height,
- InstantSizeUnits units) {
- render_view()->Send(new ChromeViewHostMsg_ShowInstantOverlay(
- render_view()->GetRoutingID(), render_view()->GetPageId(), reason,
- height, units));
-}
-
-void SearchBox::FocusOmnibox() {
- render_view()->Send(new ChromeViewHostMsg_FocusOmnibox(
- render_view()->GetRoutingID(), render_view()->GetPageId()));
-}
-
-void SearchBox::StartCapturingKeyStrokes() {
- render_view()->Send(new ChromeViewHostMsg_StartCapturingKeyStrokes(
- render_view()->GetRoutingID(), render_view()->GetPageId()));
-}
-
-void SearchBox::StopCapturingKeyStrokes() {
- render_view()->Send(new ChromeViewHostMsg_StopCapturingKeyStrokes(
- render_view()->GetRoutingID(), render_view()->GetPageId()));
-}
-
-void SearchBox::NavigateToURL(const GURL& url,
- content::PageTransition transition,
- WindowOpenDisposition disposition) {
- render_view()->Send(new ChromeViewHostMsg_SearchBoxNavigate(
- render_view()->GetRoutingID(), render_view()->GetPageId(),
- url, transition, disposition));
-}
-
-void SearchBox::DeleteMostVisitedItem(int restrict_id) {
- string16 url = RestrictedIdToURL(restrict_id);
- render_view()->Send(new ChromeViewHostMsg_InstantDeleteMostVisitedItem(
- render_view()->GetRoutingID(), GURL(url)));
-}
-
-void SearchBox::UndoMostVisitedDeletion(int restrict_id) {
- string16 url = RestrictedIdToURL(restrict_id);
- render_view()->Send(new ChromeViewHostMsg_InstantUndoMostVisitedDeletion(
- render_view()->GetRoutingID(), GURL(url)));
-}
-
-void SearchBox::UndoAllMostVisitedDeletions() {
- render_view()->Send(new ChromeViewHostMsg_InstantUndoAllMostVisitedDeletions(
- render_view()->GetRoutingID()));
-}
-
-int SearchBox::GetStartMargin() const {
- return static_cast<int>(start_margin_ / GetZoom());
-}
-
gfx::Rect SearchBox::GetPopupBounds() const {
double zoom = GetZoom();
return gfx::Rect(static_cast<int>(popup_bounds_.x() / zoom),
@@ -113,212 +28,71 @@ gfx::Rect SearchBox::GetPopupBounds() const {
static_cast<int>(popup_bounds_.height() / zoom));
}
-const std::vector<InstantAutocompleteResult>&
- SearchBox::GetAutocompleteResults() {
- // Remember the last requested autocomplete_results to account for race
- // conditions between autocomplete providers returning new data and the user
- // clicking on a suggestion.
- last_autocomplete_results_ = autocomplete_results_;
- last_results_base_ = results_base_;
- return autocomplete_results_;
-}
-
-const InstantAutocompleteResult* SearchBox::GetAutocompleteResultWithId(
- size_t restricted_id) const {
- if (restricted_id < last_results_base_ ||
- restricted_id >= last_results_base_ + last_autocomplete_results_.size())
- return NULL;
- return &last_autocomplete_results_[restricted_id - last_results_base_];
-}
-
-const ThemeBackgroundInfo& SearchBox::GetThemeBackgroundInfo() {
- return theme_info_;
+void SearchBox::SetSuggestion(const InstantSuggestion& suggestion) {
+ Send(new ChromeViewHostMsg_SearchBoxSetSuggestion(
+ routing_id(), render_view()->GetPageId(), suggestion));
}
bool SearchBox::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(SearchBox, message)
+ IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxDetermineInstantSupport,
+ OnDetermineInstantSupport)
IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxChange, OnChange)
IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSubmit, OnSubmit)
- IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxCancel, OnCancel)
- IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxPopupResize, OnPopupResize)
- IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxMarginChange, OnMarginChange)
- IPC_MESSAGE_HANDLER(ChromeViewMsg_DetermineIfPageSupportsInstant,
- OnDetermineIfPageSupportsInstant)
- IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxAutocompleteResults,
- OnAutocompleteResults)
- IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxUpOrDownKeyPressed,
- OnUpOrDownKeyPressed)
- IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxCancelSelection,
- OnCancelSelection)
- IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxSetDisplayInstantResults,
- OnSetDisplayInstantResults)
- IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxKeyCaptureChanged,
- OnKeyCaptureChange)
- IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxThemeChanged,
- OnThemeChanged)
- IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxFontInformation,
- OnFontInformationReceived)
- IPC_MESSAGE_HANDLER(
- ChromeViewMsg_SearchBoxGrantChromeSearchAccessFromOrigin,
- OnGrantChromeSearchAccessFromOrigin)
- IPC_MESSAGE_HANDLER(ChromeViewMsg_InstantMostVisitedItemsChanged,
- OnMostVisitedChanged)
+ IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxBlur, OnBlur)
+ IPC_MESSAGE_HANDLER(ChromeViewMsg_SearchBoxPopupBounds, OnPopupBounds)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
-void SearchBox::DidClearWindowObject(WebKit::WebFrame* frame) {
- extensions_v8::SearchBoxExtension::DispatchOnWindowReady(frame);
+void SearchBox::OnDetermineInstantSupport() {
+ bool supports_instant =
+ extensions_v8::SearchBoxExtension::DetermineInstantSupport(render_view());
+ Send(new ChromeViewHostMsg_SearchBoxInstantSupportDetermined(
+ routing_id(), render_view()->GetPageId(), supports_instant));
}
void SearchBox::OnChange(const string16& query,
bool verbatim,
size_t selection_start,
size_t selection_end) {
+ if (query_ == query && verbatim_ == verbatim &&
+ selection_start_ == selection_start && selection_end_ == selection_end)
+ return;
+
query_ = query;
verbatim_ = verbatim;
selection_start_ = selection_start;
selection_end_ = selection_end;
- if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
- DVLOG(1) << render_view() << " OnChange";
- extensions_v8::SearchBoxExtension::DispatchChange(
- render_view()->GetWebView()->mainFrame());
- }
+ extensions_v8::SearchBoxExtension::Change(render_view());
}
void SearchBox::OnSubmit(const string16& query) {
query_ = query;
verbatim_ = true;
- selection_start_ = selection_end_ = query_.size();
- if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
- DVLOG(1) << render_view() << " OnSubmit";
- extensions_v8::SearchBoxExtension::DispatchSubmit(
- render_view()->GetWebView()->mainFrame());
- }
+ selection_start_ = query_.size();
+ selection_end_ = query_.size();
+ extensions_v8::SearchBoxExtension::Submit(render_view());
Reset();
}
-void SearchBox::OnCancel(const string16& query) {
+void SearchBox::OnBlur(const string16& query) {
query_ = query;
verbatim_ = true;
- selection_start_ = selection_end_ = query_.size();
- if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
- DVLOG(1) << render_view() << " OnCancel";
- extensions_v8::SearchBoxExtension::DispatchCancel(
- render_view()->GetWebView()->mainFrame());
- }
+ selection_start_ = query_.size();
+ selection_end_ = query_.size();
+ extensions_v8::SearchBoxExtension::Blur(render_view());
Reset();
}
-void SearchBox::OnPopupResize(const gfx::Rect& bounds) {
- popup_bounds_ = bounds;
- if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
- DVLOG(1) << render_view() << " OnPopupResize";
- extensions_v8::SearchBoxExtension::DispatchResize(
- render_view()->GetWebView()->mainFrame());
- }
-}
-
-void SearchBox::OnMarginChange(int margin, int width) {
- start_margin_ = margin;
-
- // Override only the width parameter of the popup bounds.
- popup_bounds_.set_width(width);
-
- if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
- extensions_v8::SearchBoxExtension::DispatchMarginChange(
- render_view()->GetWebView()->mainFrame());
- }
-}
+void SearchBox::OnPopupBounds(const gfx::Rect& bounds) {
+ if (popup_bounds_ == bounds)
+ return;
-void SearchBox::OnDetermineIfPageSupportsInstant() {
- if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
- bool result = extensions_v8::SearchBoxExtension::PageSupportsInstant(
- render_view()->GetWebView()->mainFrame());
- DVLOG(1) << render_view() << " PageSupportsInstant: " << result;
- render_view()->Send(new ChromeViewHostMsg_InstantSupportDetermined(
- render_view()->GetRoutingID(), render_view()->GetPageId(), result));
- }
-}
-
-void SearchBox::OnAutocompleteResults(
- const std::vector<InstantAutocompleteResult>& results) {
- results_base_ += autocomplete_results_.size();
- autocomplete_results_ = results;
- if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
- DVLOG(1) << render_view() << " OnAutocompleteResults";
- extensions_v8::SearchBoxExtension::DispatchAutocompleteResults(
- render_view()->GetWebView()->mainFrame());
- }
-}
-
-void SearchBox::OnUpOrDownKeyPressed(int count) {
- if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
- DVLOG(1) << render_view() << " OnKeyPress: " << count;
- extensions_v8::SearchBoxExtension::DispatchUpOrDownKeyPress(
- render_view()->GetWebView()->mainFrame(), count);
- }
-}
-
-void SearchBox::OnCancelSelection(const string16& query) {
- // TODO(sreeram): crbug.com/176101 The state reset below are somewhat wrong.
- query_ = query;
- verbatim_ = true;
- selection_start_ = selection_end_ = query_.size();
- if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
- DVLOG(1) << render_view() << " OnKeyPress ESC";
- extensions_v8::SearchBoxExtension::DispatchEscKeyPress(
- render_view()->GetWebView()->mainFrame());
- }
-}
-
-void SearchBox::OnKeyCaptureChange(bool is_key_capture_enabled) {
- if (is_key_capture_enabled != is_key_capture_enabled_ &&
- render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
- is_key_capture_enabled_ = is_key_capture_enabled;
- DVLOG(1) << render_view() << " OnKeyCaptureChange";
- extensions_v8::SearchBoxExtension::DispatchKeyCaptureChange(
- render_view()->GetWebView()->mainFrame());
- }
-}
-
-void SearchBox::OnSetDisplayInstantResults(bool display_instant_results) {
- display_instant_results_ = display_instant_results;
-}
-
-void SearchBox::OnThemeChanged(const ThemeBackgroundInfo& theme_info) {
- theme_info_ = theme_info;
- if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
- extensions_v8::SearchBoxExtension::DispatchThemeChange(
- render_view()->GetWebView()->mainFrame());
- }
-}
-
-void SearchBox::OnFontInformationReceived(const string16& omnibox_font,
- size_t omnibox_font_size) {
- omnibox_font_ = omnibox_font;
- omnibox_font_size_ = omnibox_font_size;
-}
-
-void SearchBox::OnGrantChromeSearchAccessFromOrigin(const GURL& origin_url) {
- string16 chrome_search_scheme(ASCIIToUTF16(chrome::kChromeSearchScheme));
- WebKit::WebSecurityPolicy::addOriginAccessWhitelistEntry(
- origin_url,
- chrome_search_scheme,
- ASCIIToUTF16(chrome::kChromeUIFaviconHost),
- false);
- WebKit::WebSecurityPolicy::addOriginAccessWhitelistEntry(
- origin_url,
- chrome_search_scheme,
- ASCIIToUTF16(chrome::kChromeUIThemeHost),
- false);
- WebKit::WebSecurityPolicy::addOriginAccessWhitelistEntry(
- origin_url,
- chrome_search_scheme,
- ASCIIToUTF16(chrome::kChromeUIThumbnailHost),
- false);
+ popup_bounds_ = bounds;
+ extensions_v8::SearchBoxExtension::PopupBounds(render_view());
}
double SearchBox::GetZoom() const {
@@ -336,58 +110,5 @@ void SearchBox::Reset() {
verbatim_ = false;
selection_start_ = 0;
selection_end_ = 0;
- results_base_ = 0;
popup_bounds_ = gfx::Rect();
- start_margin_ = 0;
- autocomplete_results_.clear();
- is_key_capture_enabled_ = false;
- theme_info_ = ThemeBackgroundInfo();
- // Don't reset display_instant_results_ to prevent clearing it on committed
- // results pages in extended mode. Otherwise resetting it is a no-op because
- // a new loader is created when it changes; see crbug.com/164662.
- // Also don't reset omnibox_font_ or omnibox_font_size_ since it never
- // changes.
-}
-
-void SearchBox::OnMostVisitedChanged(
- const std::vector<MostVisitedItem>& items) {
- most_visited_items_ = items;
-
- if (render_view()->GetWebView() && render_view()->GetWebView()->mainFrame()) {
- extensions_v8::SearchBoxExtension::DispatchMostVisitedChanged(
- render_view()->GetWebView()->mainFrame());
- }
-}
-
-const std::vector<MostVisitedItem>& SearchBox::GetMostVisitedItems() {
- return most_visited_items_;
-}
-
-int SearchBox::UrlToRestrictedId(string16 url) {
- if (url_to_restricted_id_map_[url])
- return url_to_restricted_id_map_[url];
-
- last_restricted_id_++;
- url_to_restricted_id_map_[url] = last_restricted_id_;
- restricted_id_to_url_map_[last_restricted_id_] = url;
-
- return last_restricted_id_;
-}
-
-string16 SearchBox::RestrictedIdToURL(int id) {
- return restricted_id_to_url_map_[id];
-}
-
-string16 SearchBox::GenerateThumbnailUrl(int id) {
- std::ostringstream ostr;
- ostr << kThumbnailUrlPrefix << id;
- GURL url = GURL(ostr.str());
- return UTF8ToUTF16(url.spec());
-}
-
-string16 SearchBox::GenerateFaviconUrl(int id) {
- std::ostringstream ostr;
- ostr << kFaviconUrlPrefix << id;
- GURL url = GURL(ostr.str());
- return UTF8ToUTF16(url.spec());
}

Powered by Google App Engine
This is Rietveld 408576698