diff options
-rw-r--r-- | chrome/browser/instant/instant_loader.cc | 14 | ||||
-rw-r--r-- | chrome/chrome_common.gypi | 1 | ||||
-rw-r--r-- | chrome/common/instant_types.h | 21 | ||||
-rw-r--r-- | chrome/common/render_messages.h | 6 | ||||
-rw-r--r-- | chrome/common/render_messages_internal.h | 6 | ||||
-rw-r--r-- | chrome/renderer/search_extension.cc | 2 | ||||
-rw-r--r-- | chrome/renderer/searchbox.cc | 6 | ||||
-rw-r--r-- | chrome/renderer/searchbox.h | 4 | ||||
-rw-r--r-- | chrome/renderer/searchbox_extension.cc | 13 | ||||
-rw-r--r-- | content/browser/tab_contents/tab_contents.cc | 5 | ||||
-rw-r--r-- | content/browser/tab_contents/tab_contents.h | 4 | ||||
-rw-r--r-- | content/browser/tab_contents/tab_contents_delegate.cc | 3 | ||||
-rw-r--r-- | content/browser/tab_contents/tab_contents_delegate.h | 4 |
13 files changed, 73 insertions, 16 deletions
diff --git a/chrome/browser/instant/instant_loader.cc b/chrome/browser/instant/instant_loader.cc index f29dec8..15c251e 100644 --- a/chrome/browser/instant/instant_loader.cc +++ b/chrome/browser/instant/instant_loader.cc @@ -214,7 +214,8 @@ class InstantLoader::TabContentsDelegateImpl NavigationType::Type navigation_type) OVERRIDE; virtual void OnSetSuggestions( int32 page_id, - const std::vector<std::string>& suggestions) OVERRIDE; + const std::vector<std::string>& suggestions, + InstantCompleteBehavior behavior) OVERRIDE; virtual void OnInstantSupportDetermined(int32 page_id, bool result) OVERRIDE; virtual bool ShouldShowHungRendererDialog() OVERRIDE; @@ -521,14 +522,14 @@ bool InstantLoader::TabContentsDelegateImpl::ShouldAddNavigationToHistory( void InstantLoader::TabContentsDelegateImpl::OnSetSuggestions( int32 page_id, - const std::vector<std::string>& suggestions) { + const std::vector<std::string>& suggestions, + InstantCompleteBehavior behavior) { TabContentsWrapper* source = loader_->preview_contents(); if (!source->controller().GetActiveEntry() || page_id != source->controller().GetActiveEntry()->page_id()) return; - // TODO: only allow for default search provider. - // TODO(sky): Handle multiple suggestions. + // TODO: pass in behavior to SetCompleteSuggestedText. if (suggestions.empty()) loader_->SetCompleteSuggestedText(string16()); else @@ -778,6 +779,11 @@ void InstantLoader::CommitInstantLoader() { void InstantLoader::SetCompleteSuggestedText( const string16& complete_suggested_text) { + if (!is_showing_instant()) { + // We're not trying to use the instant API with this page. Ignore it. + return; + } + ShowPreview(); if (complete_suggested_text == complete_suggested_text_) diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index b0c342f..50ba4c0 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -83,6 +83,7 @@ 'common/indexed_db_messages.h', 'common/indexed_db_param_traits.cc', 'common/indexed_db_param_traits.h', + 'common/instant_types.h', 'common/logging_chrome.cc', 'common/logging_chrome.h', 'common/main_function_params.h', diff --git a/chrome/common/instant_types.h b/chrome/common/instant_types.h new file mode 100644 index 0000000..cad7cbf --- /dev/null +++ b/chrome/common/instant_types.h @@ -0,0 +1,21 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_COMMON_INSTANT_TYPES_H_ +#define CHROME_COMMON_INSTANT_TYPES_H_ +#pragma once + +// Enum describing the ways instant suggest text can be completed. +enum InstantCompleteBehavior { + // Complete the suggestion now. + INSTANT_COMPLETE_NOW, + + // Complete the suggestion after a delay. + INSTANT_COMPLETE_DELAYED, + + // Never complete the suggestion. + INSTANT_COMPLETE_NEVER +}; + +#endif // CHROME_COMMON_INSTANT_TYPES_H_ diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index a9d548d..1dce706 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -16,6 +16,7 @@ #include "base/string16.h" #include "chrome/common/common_param_traits.h" #include "chrome/common/css_colors.h" +#include "chrome/common/instant_types.h" #include "chrome/common/page_transition_types.h" #include "chrome/common/translate_errors.h" #include "chrome/common/view_types.h" @@ -378,6 +379,11 @@ struct SimilarTypeTraits<TranslateErrors::Type> { }; template <> +struct SimilarTypeTraits<InstantCompleteBehavior> { + typedef int Type; +}; + +template <> struct ParamTraits<ExtensionExtent> { typedef ExtensionExtent param_type; static void Write(Message* m, const param_type& p); diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h index 58a9efa..6873afe 100644 --- a/chrome/common/render_messages_internal.h +++ b/chrome/common/render_messages_internal.h @@ -18,6 +18,7 @@ #include "chrome/common/content_settings.h" #include "chrome/common/extensions/extension.h" #include "chrome/common/geoposition.h" +#include "chrome/common/instant_types.h" #include "chrome/common/nacl_types.h" #include "chrome/common/page_zoom.h" #include "chrome/common/translate_errors.h" @@ -2217,9 +2218,10 @@ IPC_MESSAGE_CONTROL1(ViewHostMsg_UnregisterBlobUrl, GURL /* url */) // Suggest results ----------------------------------------------------------- -IPC_MESSAGE_ROUTED2(ViewHostMsg_SetSuggestions, +IPC_MESSAGE_ROUTED3(ViewHostMsg_SetSuggestions, int32 /* page_id */, - std::vector<std::string> /* suggestions */) + std::vector<std::string> /* suggestions */, + InstantCompleteBehavior) IPC_MESSAGE_ROUTED2(ViewHostMsg_InstantSupportDetermined, int32 /* page_id */, diff --git a/chrome/renderer/search_extension.cc b/chrome/renderer/search_extension.cc index ee71cf6..4c9e28f 100644 --- a/chrome/renderer/search_extension.cc +++ b/chrome/renderer/search_extension.cc @@ -83,7 +83,7 @@ v8::Handle<v8::Value> SearchExtensionWrapper::SetSuggestResult( std::vector<std::string> suggestions; suggestions.push_back(std::string(*v8::String::Utf8Value(args[0]))); - render_view->searchbox()->SetSuggestions(suggestions); + render_view->searchbox()->SetSuggestions(suggestions, INSTANT_COMPLETE_NOW); return v8::Undefined(); } diff --git a/chrome/renderer/searchbox.cc b/chrome/renderer/searchbox.cc index c8aac0f..dd5bf08 100644 --- a/chrome/renderer/searchbox.cc +++ b/chrome/renderer/searchbox.cc @@ -21,10 +21,12 @@ SearchBox::SearchBox(RenderView* render_view) SearchBox::~SearchBox() { } -void SearchBox::SetSuggestions(const std::vector<std::string>& suggestions) { +void SearchBox::SetSuggestions(const std::vector<std::string>& suggestions, + InstantCompleteBehavior behavior) { // Explicitly allow empty vector to be sent to the browser. render_view()->Send(new ViewHostMsg_SetSuggestions( - render_view()->routing_id(), render_view()->page_id(), suggestions)); + render_view()->routing_id(), render_view()->page_id(), suggestions, + behavior)); } bool SearchBox::OnMessageReceived(const IPC::Message& message) { diff --git a/chrome/renderer/searchbox.h b/chrome/renderer/searchbox.h index f2fd164..5903682 100644 --- a/chrome/renderer/searchbox.h +++ b/chrome/renderer/searchbox.h @@ -10,6 +10,7 @@ #include "base/string16.h" #include "chrome/renderer/render_view_observer.h" +#include "chrome/common/instant_types.h" #include "ui/gfx/rect.h" class SearchBox : public RenderViewObserver { @@ -18,7 +19,8 @@ class SearchBox : public RenderViewObserver { ~SearchBox(); // Sends ViewHostMsg_SetSuggestions to the browser. - void SetSuggestions(const std::vector<std::string>& suggestions); + void SetSuggestions(const std::vector<std::string>& suggestions, + InstantCompleteBehavior behavior); const string16& value() { return value_; } bool verbatim() { return verbatim_; } diff --git a/chrome/renderer/searchbox_extension.cc b/chrome/renderer/searchbox_extension.cc index 36fc94c..c1b9bfe 100644 --- a/chrome/renderer/searchbox_extension.cc +++ b/chrome/renderer/searchbox_extension.cc @@ -289,6 +289,7 @@ v8::Handle<v8::Value> SearchBoxExtensionWrapper::GetHeight( v8::Handle<v8::Value> SearchBoxExtensionWrapper::SetSuggestions( const v8::Arguments& args) { std::vector<std::string> suggestions; + InstantCompleteBehavior behavior = INSTANT_COMPLETE_NOW; if (args.Length() && args[0]->IsArray()) { // For backwards compatibility, also accept an array of strings. @@ -329,10 +330,20 @@ v8::Handle<v8::Value> SearchBoxExtensionWrapper::SetSuggestions( suggestions.push_back(suggestion); } } + if (suggestion_json->Has(v8::String::New("complete_behavior"))) { + v8::Local<v8::Value> complete_value = + suggestion_json->Get(v8::String::New("complete_behavior")); + if (complete_value->IsString()) { + if (complete_value->Equals(v8::String::New("never"))) + behavior = INSTANT_COMPLETE_NEVER; + else if (complete_value->Equals(v8::String::New("delayed"))) + behavior = INSTANT_COMPLETE_DELAYED; + } + } } if (RenderView* render_view = GetRenderView()) - render_view->searchbox()->SetSuggestions(suggestions); + render_view->searchbox()->SetSuggestions(suggestions, behavior); return v8::Undefined(); } diff --git a/content/browser/tab_contents/tab_contents.cc b/content/browser/tab_contents/tab_contents.cc index 6281f13..3b88d16 100644 --- a/content/browser/tab_contents/tab_contents.cc +++ b/content/browser/tab_contents/tab_contents.cc @@ -1967,9 +1967,10 @@ void TabContents::OnPageTranslated(int32 page_id, void TabContents::OnSetSuggestions( int32 page_id, - const std::vector<std::string>& suggestions) { + const std::vector<std::string>& suggestions, + InstantCompleteBehavior behavior) { if (delegate()) - delegate()->OnSetSuggestions(page_id, suggestions); + delegate()->OnSetSuggestions(page_id, suggestions, behavior); } void TabContents::OnInstantSupportDetermined(int32 page_id, bool result) { diff --git a/content/browser/tab_contents/tab_contents.h b/content/browser/tab_contents/tab_contents.h index 031a28f..4495409 100644 --- a/content/browser/tab_contents/tab_contents.h +++ b/content/browser/tab_contents/tab_contents.h @@ -21,6 +21,7 @@ #include "chrome/browser/prefs/pref_change_registrar.h" #include "chrome/browser/tab_contents/tab_specific_content_settings.h" #include "chrome/browser/ui/app_modal_dialogs/js_modal_dialog.h" +#include "chrome/common/instant_types.h" #include "chrome/common/renderer_preferences.h" #include "chrome/common/translate_errors.h" #include "chrome/common/web_apps.h" @@ -797,7 +798,8 @@ class TabContents : public PageNavigator, const std::string& translated_lang, TranslateErrors::Type error_type); void OnSetSuggestions(int32 page_id, - const std::vector<std::string>& suggestions); + const std::vector<std::string>& suggestions, + InstantCompleteBehavior complete_behavior); void OnInstantSupportDetermined(int32 page_id, bool result); void OnRunFileChooser(const ViewHostMsg_RunFileChooser_Params& params); diff --git a/content/browser/tab_contents/tab_contents_delegate.cc b/content/browser/tab_contents/tab_contents_delegate.cc index c059b57..0d099cb 100644 --- a/content/browser/tab_contents/tab_contents_delegate.cc +++ b/content/browser/tab_contents/tab_contents_delegate.cc @@ -219,7 +219,8 @@ void TabContentsDelegate::UpdatePreferredSize(const gfx::Size& pref_size) { void TabContentsDelegate::OnSetSuggestions( int32 page_id, - const std::vector<std::string>& suggestions) { + const std::vector<std::string>& suggestions, + InstantCompleteBehavior behavior) { } void TabContentsDelegate::OnInstantSupportDetermined(int32 page_id, diff --git a/content/browser/tab_contents/tab_contents_delegate.h b/content/browser/tab_contents/tab_contents_delegate.h index 381dfff..6264575 100644 --- a/content/browser/tab_contents/tab_contents_delegate.h +++ b/content/browser/tab_contents/tab_contents_delegate.h @@ -12,6 +12,7 @@ #include "base/basictypes.h" #include "chrome/browser/automation/automation_resource_routing_delegate.h" #include "chrome/common/content_settings_types.h" +#include "chrome/common/instant_types.h" #include "chrome/common/navigation_types.h" #include "chrome/common/page_transition_types.h" #include "content/browser/tab_contents/navigation_entry.h" @@ -314,7 +315,8 @@ class TabContentsDelegate : public AutomationResourceRoutingDelegate { // Notifies the delegate that the page has a suggest result. virtual void OnSetSuggestions(int32 page_id, - const std::vector<std::string>& result); + const std::vector<std::string>& result, + InstantCompleteBehavior behavior); // Notifies the delegate whether the page supports instant-style interaction. virtual void OnInstantSupportDetermined(int32 page_id, bool result); |