diff options
25 files changed, 283 insertions, 217 deletions
diff --git a/chrome/browser/DEPS b/chrome/browser/DEPS index 21f190f..eb351ab 100644 --- a/chrome/browser/DEPS +++ b/chrome/browser/DEPS @@ -47,6 +47,7 @@ include_rules = [ "+components/pref_registry", "+components/query_parser", "+components/rappor", + "+components/renderer_context_menu", "+components/search", "+components/search_engines", "+components/search_provider_logos", diff --git a/chrome/browser/guest_view/app_view/app_view_guest.cc b/chrome/browser/guest_view/app_view/app_view_guest.cc index bd77a66..85e9d52d 100644 --- a/chrome/browser/guest_view/app_view/app_view_guest.cc +++ b/chrome/browser/guest_view/app_view/app_view_guest.cc @@ -9,9 +9,9 @@ #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/guest_view/app_view/app_view_constants.h" #include "chrome/browser/guest_view/guest_view_manager.h" -#include "chrome/browser/renderer_context_menu/context_menu_delegate.h" #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" #include "chrome/common/chrome_switches.h" +#include "components/renderer_context_menu/context_menu_delegate.h" #include "content/public/browser/render_view_host.h" #include "content/public/common/renderer_preferences.h" #include "extensions/browser/api/app_runtime/app_runtime_api.h" diff --git a/chrome/browser/guest_view/web_view/web_view_guest.cc b/chrome/browser/guest_view/web_view/web_view_guest.cc index 5e1c395..a404477 100644 --- a/chrome/browser/guest_view/web_view/web_view_guest.cc +++ b/chrome/browser/guest_view/web_view/web_view_guest.cc @@ -20,13 +20,13 @@ #include "chrome/browser/guest_view/web_view/web_view_permission_helper.h" #include "chrome/browser/guest_view/web_view/web_view_permission_types.h" #include "chrome/browser/guest_view/web_view/web_view_renderer_state.h" -#include "chrome/browser/renderer_context_menu/context_menu_delegate.h" #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" #include "chrome/browser/ui/pdf/pdf_tab_helper.h" #include "chrome/browser/ui/zoom/zoom_controller.h" #include "chrome/common/chrome_version_info.h" #include "chrome/common/extensions/chrome_extension_messages.h" #include "chrome/common/render_messages.h" +#include "components/renderer_context_menu/context_menu_delegate.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/child_process_security_policy.h" #include "content/public/browser/native_web_keyboard_event.h" diff --git a/chrome/browser/printing/print_preview_context_menu_observer.h b/chrome/browser/printing/print_preview_context_menu_observer.h index 9b5eb57..8c05e53 100644 --- a/chrome/browser/printing/print_preview_context_menu_observer.h +++ b/chrome/browser/printing/print_preview_context_menu_observer.h @@ -7,7 +7,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" -#include "chrome/browser/renderer_context_menu/render_view_context_menu_observer.h" +#include "components/renderer_context_menu/render_view_context_menu_observer.h" namespace content { class WebContents; diff --git a/chrome/browser/renderer_context_menu/render_view_context_menu.cc b/chrome/browser/renderer_context_menu/render_view_context_menu.cc index 1eddc69..de8539e 100644 --- a/chrome/browser/renderer_context_menu/render_view_context_menu.cc +++ b/chrome/browser/renderer_context_menu/render_view_context_menu.cc @@ -69,6 +69,7 @@ #include "components/translate/core/browser/translate_download_manager.h" #include "components/translate/core/browser/translate_manager.h" #include "components/translate/core/browser/translate_prefs.h" +#include "components/user_prefs/user_prefs.h" #include "content/public/browser/child_process_security_policy.h" #include "content/public/browser/download_manager.h" #include "content/public/browser/download_save_info.h" @@ -383,6 +384,11 @@ void EscapeAmpersands(base::string16* text) { text); } +// Returns the preference of the profile represented by the |context|. +PrefService* GetPrefs(content::BrowserContext* context) { + return user_prefs::UserPrefs::Get(context); +} + } // namespace // static @@ -409,16 +415,15 @@ RenderViewContextMenu::RenderViewContextMenu( source_web_contents_(WebContents::FromRenderFrameHost(render_frame_host)), render_process_id_(render_frame_host->GetProcess()->GetID()), render_frame_id_(render_frame_host->GetRoutingID()), - profile_(Profile::FromBrowserContext( - source_web_contents_->GetBrowserContext())), + browser_context_(source_web_contents_->GetBrowserContext()), menu_model_(this), - extension_items_(profile_, + extension_items_(browser_context_, this, &menu_model_, base::Bind(MenuItemMatchesParams, params_)), protocol_handler_submenu_model_(this), protocol_handler_registry_( - ProtocolHandlerRegistryFactory::GetForProfile(profile_)), + ProtocolHandlerRegistryFactory::GetForProfile(GetProfile())), command_executed_(false) { content_type_.reset(ContextMenuContentTypeFactory::Create( source_web_contents_, params)); @@ -519,11 +524,11 @@ bool RenderViewContextMenu::MenuItemMatchesParams( void RenderViewContextMenu::AppendAllExtensionItems() { extension_items_.Clear(); ExtensionService* service = - extensions::ExtensionSystem::Get(profile_)->extension_service(); + extensions::ExtensionSystem::Get(browser_context_)->extension_service(); if (!service) return; // In unit-tests, we may not have an ExtensionService. - MenuManager* menu_manager = MenuManager::Get(profile_); + MenuManager* menu_manager = MenuManager::Get(browser_context_); if (!menu_manager) return; @@ -691,6 +696,10 @@ void RenderViewContextMenu::InitMenu() { } } +Profile* RenderViewContextMenu::GetProfile() { + return Profile::FromBrowserContext(browser_context_); +} + void RenderViewContextMenu::AppendPrintPreviewItems() { #if defined(ENABLE_FULL_PRINTING) if (!print_preview_menu_observer_.get()) { @@ -704,7 +713,7 @@ void RenderViewContextMenu::AppendPrintPreviewItems() { const Extension* RenderViewContextMenu::GetExtension() const { extensions::ExtensionSystem* system = - extensions::ExtensionSystem::Get(profile_); + extensions::ExtensionSystem::Get(browser_context_); // There is no process manager in some tests. if (!system->process_manager()) return NULL; @@ -749,8 +758,8 @@ WebContents* RenderViewContextMenu::GetWebContents() const { return source_web_contents_; } -Profile* RenderViewContextMenu::GetProfile() const { - return profile_; +BrowserContext* RenderViewContextMenu::GetBrowserContext() const { + return browser_context_; } bool RenderViewContextMenu::AppendCustomItems() { @@ -828,7 +837,7 @@ void RenderViewContextMenu::AppendImageItems() { void RenderViewContextMenu::AppendSearchWebForImageItems() { TemplateURLService* service = - TemplateURLServiceFactory::GetForProfile(profile_); + TemplateURLServiceFactory::GetForProfile(GetProfile()); const TemplateURL* const default_provider = service->GetDefaultSearchProvider(); if (params_.has_image_contents && default_provider && @@ -955,7 +964,7 @@ void RenderViewContextMenu::AppendCopyItem() { } void RenderViewContextMenu::AppendPrintItem() { - if (profile_->GetPrefs()->GetBoolean(prefs::kPrintingEnabled) && + if (GetPrefs(browser_context_)->GetBoolean(prefs::kPrintingEnabled) && (params_.media_type == WebContextMenuData::MediaTypeNone || params_.media_flags & WebContextMenuData::MediaCanPrint)) { menu_model_.AddItemWithStringId(IDC_PRINT, IDS_CONTENT_CONTEXT_PRINT); @@ -963,7 +972,7 @@ void RenderViewContextMenu::AppendPrintItem() { } void RenderViewContextMenu::AppendSearchProvider() { - DCHECK(profile_); + DCHECK(browser_context_); base::TrimWhitespace(params_.selection_text, base::TRIM_ALL, ¶ms_.selection_text); @@ -974,9 +983,13 @@ void RenderViewContextMenu::AppendSearchProvider() { base::ASCIIToUTF16(" "), ¶ms_.selection_text); AutocompleteMatch match; - AutocompleteClassifierFactory::GetForProfile(profile_)->Classify( - params_.selection_text, false, false, - metrics::OmniboxEventProto::INVALID_SPEC, &match, NULL); + AutocompleteClassifierFactory::GetForProfile(GetProfile()) + ->Classify(params_.selection_text, + false, + false, + metrics::OmniboxEventProto::INVALID_SPEC, + &match, + NULL); selection_navigation_url_ = match.destination_url; if (!selection_navigation_url_.is_valid()) return; @@ -986,8 +999,8 @@ void RenderViewContextMenu::AppendSearchProvider() { if (AutocompleteMatch::IsSearchType(match.type)) { const TemplateURL* const default_provider = - TemplateURLServiceFactory::GetForProfile(profile_)-> - GetDefaultSearchProvider(); + TemplateURLServiceFactory::GetForProfile(GetProfile()) + ->GetDefaultSearchProvider(); if (!default_provider) return; menu_model_.AddItem( @@ -1112,10 +1125,12 @@ bool RenderViewContextMenu::IsCommandIdEnabled(int id) const { return false; } + PrefService* prefs = GetPrefs(browser_context_); + // Allow Spell Check language items on sub menu for text area context menu. if ((id >= IDC_SPELLCHECK_LANGUAGES_FIRST) && (id < IDC_SPELLCHECK_LANGUAGES_LAST)) { - return profile_->GetPrefs()->GetBoolean(prefs::kEnableContinuousSpellcheck); + return prefs->GetBoolean(prefs::kEnableContinuousSpellcheck); } // Custom items. @@ -1136,7 +1151,7 @@ bool RenderViewContextMenu::IsCommandIdEnabled(int id) const { } IncognitoModePrefs::Availability incognito_avail = - IncognitoModePrefs::GetAvailability(profile_->GetPrefs()); + IncognitoModePrefs::GetAvailability(prefs); switch (id) { case IDC_BACK: return source_web_contents_->GetController().CanGoBack(); @@ -1340,13 +1355,14 @@ bool RenderViewContextMenu::IsCommandIdEnabled(int id) const { return !!(params_.edit_flags & WebContextMenuData::CanSelectAll); case IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD: - return !profile_->IsOffTheRecord() && params_.link_url.is_valid() && + return !browser_context_->IsOffTheRecord() && + params_.link_url.is_valid() && incognito_avail != IncognitoModePrefs::DISABLED; case IDC_PRINT: - return profile_->GetPrefs()->GetBoolean(prefs::kPrintingEnabled) && - (params_.media_type == WebContextMenuData::MediaTypeNone || - params_.media_flags & WebContextMenuData::MediaCanPrint); + return prefs->GetBoolean(prefs::kPrintingEnabled) && + (params_.media_type == WebContextMenuData::MediaTypeNone || + params_.media_flags & WebContextMenuData::MediaCanPrint); case IDC_CONTENT_CONTEXT_SEARCHWEBFOR: case IDC_CONTENT_CONTEXT_GOTOURL: @@ -1360,8 +1376,7 @@ bool RenderViewContextMenu::IsCommandIdEnabled(int id) const { return true; case IDC_CHECK_SPELLING_WHILE_TYPING: - return profile_->GetPrefs()->GetBoolean( - prefs::kEnableContinuousSpellcheck); + return prefs->GetBoolean(prefs::kEnableContinuousSpellcheck); #if !defined(OS_MACOSX) && defined(OS_POSIX) // TODO(suzhe): this should not be enabled for password fields. @@ -1509,7 +1524,8 @@ void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) { const GURL& referrer = params_.frame_url.is_empty() ? params_.page_url : params_.frame_url; const GURL& url = params_.link_url; - DownloadManager* dlm = BrowserContext::GetDownloadManager(profile_); + DownloadManager* dlm = + BrowserContext::GetDownloadManager(browser_context_); scoped_ptr<DownloadUrlParameters> dl_params( DownloadUrlParameters::FromWebContents(source_web_contents_, url)); dl_params->set_referrer( @@ -1647,8 +1663,9 @@ void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) { DCHECK(platform_app); DCHECK(platform_app->is_platform_app()); - extensions::ExtensionSystem::Get(profile_)->extension_service()-> - ReloadExtension(platform_app->id()); + extensions::ExtensionSystem::Get(browser_context_) + ->extension_service() + ->ReloadExtension(platform_app->id()); break; } @@ -1657,8 +1674,8 @@ void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) { DCHECK(platform_app); DCHECK(platform_app->is_platform_app()); - apps::AppLoadService::Get(profile_)->RestartApplication( - platform_app->id()); + apps::AppLoadService::Get(GetProfile()) + ->RestartApplication(platform_app->id()); break; } @@ -1671,7 +1688,8 @@ void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) { if (!print_view_manager) break; - if (profile_->GetPrefs()->GetBoolean(prefs::kPrintPreviewDisabled)) { + if (GetPrefs(browser_context_) + ->GetBoolean(prefs::kPrintPreviewDisabled)) { print_view_manager->PrintNow(); } else { print_view_manager->PrintPreviewNow(!params_.selection_text.empty()); @@ -1706,7 +1724,8 @@ void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) { DCHECK(platform_app); DCHECK(platform_app->is_platform_app()); - extensions::devtools_util::InspectBackgroundPage(platform_app, profile_); + extensions::devtools_util::InspectBackgroundPage(platform_app, + GetProfile()); break; } @@ -1742,7 +1761,8 @@ void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) { // Since the user decided to translate for that language and site, clears // any preferences for not translating them. scoped_ptr<translate::TranslatePrefs> prefs( - ChromeTranslateClient::CreateTranslatePrefs(profile_->GetPrefs())); + ChromeTranslateClient::CreateTranslatePrefs( + GetPrefs(browser_context_))); prefs->UnblockLanguage(original_lang); prefs->RemoveSiteFromBlacklist(params_.page_url.HostNoBrackets()); translate::TranslateManager* manager = @@ -1833,7 +1853,7 @@ void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) { case IDC_CONTENT_CONTEXT_ADDSEARCHENGINE: { // Make sure the model is loaded. TemplateURLService* model = - TemplateURLServiceFactory::GetForProfile(profile_); + TemplateURLServiceFactory::GetForProfile(GetProfile()); if (!model) return; model->Load(); @@ -1850,8 +1870,8 @@ void RenderViewContextMenu::ExecuteCommand(int id, int event_flags) { data.favicon_url = TemplateURL::GenerateFaviconURL(params_.page_url.GetOrigin()); // Takes ownership of the TemplateURL. - search_engine_tab_helper->delegate()-> - ConfirmAddSearchProvider(new TemplateURL(data), profile_); + search_engine_tab_helper->delegate()->ConfirmAddSearchProvider( + new TemplateURL(data), GetProfile()); } break; } @@ -1915,13 +1935,14 @@ bool RenderViewContextMenu::IsDevCommandEnabled(int id) const { if (id == IDC_CONTENT_CONTEXT_INSPECTELEMENT || id == IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE) { const CommandLine* command_line = CommandLine::ForCurrentProcess(); - if (!profile_->GetPrefs()->GetBoolean(prefs::kWebKitJavascriptEnabled) || + if (!GetPrefs(browser_context_) + ->GetBoolean(prefs::kWebKitJavascriptEnabled) || command_line->HasSwitch(switches::kDisableJavaScript)) return false; // Don't enable the web inspector if the developer tools are disabled via // the preference dev-tools-disabled. - if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) + if (GetPrefs(browser_context_)->GetBoolean(prefs::kDevToolsDisabled)) return false; } @@ -1959,8 +1980,7 @@ void RenderViewContextMenu::OpenURL( details.not_yet_in_tabstrip = false; content::NotificationService::current()->Notify( chrome::NOTIFICATION_RETARGETING, - content::Source<Profile>(Profile::FromBrowserContext( - source_web_contents_->GetBrowserContext())), + content::Source<Profile>(GetProfile()), content::Details<RetargetingDetails>(&details)); } @@ -1992,7 +2012,7 @@ void RenderViewContextMenu::Inspect(int x, int y) { void RenderViewContextMenu::WriteURLToClipboard(const GURL& url) { chrome_common_net::WriteURLToClipboard( url, - profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), + GetPrefs(browser_context_)->GetString(prefs::kAcceptLanguages), ui::Clipboard::GetForCurrentThread()); } diff --git a/chrome/browser/renderer_context_menu/render_view_context_menu.h b/chrome/browser/renderer_context_menu/render_view_context_menu.h index 0d1c174..da8c38b 100644 --- a/chrome/browser/renderer_context_menu/render_view_context_menu.h +++ b/chrome/browser/renderer_context_menu/render_view_context_menu.h @@ -15,7 +15,8 @@ #include "chrome/browser/extensions/context_menu_matcher.h" #include "chrome/browser/extensions/menu_manager.h" #include "chrome/browser/renderer_context_menu/context_menu_content_type.h" -#include "chrome/browser/renderer_context_menu/render_view_context_menu_observer.h" +#include "components/renderer_context_menu/render_view_context_menu_observer.h" +#include "components/renderer_context_menu/render_view_context_menu_proxy.h" #include "content/public/common/context_menu_params.h" #include "content/public/common/page_transition_types.h" #include "ui/base/models/simple_menu_model.h" @@ -28,7 +29,6 @@ class SpellCheckerSubMenuObserver; namespace content { class RenderFrameHost; -class RenderViewHost; class WebContents; } @@ -46,85 +46,6 @@ struct WebMediaPlayerAction; struct WebPluginAction; } -// An interface that controls a RenderViewContextMenu instance from observers. -// This interface is designed mainly for controlling the instance while showing -// so we can add a context-menu item that takes long time to create its text, -// such as retrieving the item text from a server. The simplest usage is: -// 1. Adding an item with temporary text; -// 2. Posting a background task that creates the item text, and; -// 3. Calling UpdateMenuItem() in the callback function. -// The following snippet describes the simple usage that updates a context-menu -// item with this interface. -// -// class MyTask : public net::URLFetcherDelegate { -// public: -// MyTask(RenderViewContextMenuProxy* proxy, int id) -// : proxy_(proxy), -// id_(id) { -// } -// virtual ~MyTask() { -// } -// virtual void OnURLFetchComplete(const net::URLFetcher* source, -// const GURL& url, -// const net::URLRequestStatus& status, -// int response, -// const net::ResponseCookies& cookies, -// const std::string& data) { -// bool enabled = response == 200; -// const char* text = enabled ? "OK" : "ERROR"; -// proxy_->UpdateMenuItem(id_, enabled, base::ASCIIToUTF16(text)); -// } -// void Start(const GURL* url, net::URLRequestContextGetter* context) { -// fetcher_.reset(new URLFetcher(url, URLFetcher::GET, this)); -// fetcher_->SetRequestContext(context); -// content::AssociateURLFetcherWithRenderView( -// fetcher_.get(), -// proxy_->GetRenderViewHost()->GetSiteInstance()->GetSite(), -// proxy_->GetRenderViewHost()->GetProcess()->GetID(), -// proxy_->GetRenderViewHost()->GetRoutingID()); -// fetcher_->Start(); -// } -// -// private: -// URLFetcher fetcher_; -// RenderViewContextMenuProxy* proxy_; -// int id_; -// }; -// -// void RenderViewContextMenu::AppendEditableItems() { -// // Add a menu item with temporary text shown while we create the final -// // text. -// menu_model_.AddItemWithStringId(IDC_MY_ITEM, IDC_MY_TEXT); -// -// // Start a task that creates the final text. -// my_task_ = new MyTask(this, IDC_MY_ITEM); -// my_task_->Start(...); -// } -// -class RenderViewContextMenuProxy { - public: - // Add a menu item to a context menu. - virtual void AddMenuItem(int command_id, const base::string16& title) = 0; - virtual void AddCheckItem(int command_id, const base::string16& title) = 0; - virtual void AddSeparator() = 0; - - // Add a submenu item to a context menu. - virtual void AddSubMenu(int command_id, - const base::string16& label, - ui::MenuModel* model) = 0; - - // Update the status and text of the specified context-menu item. - virtual void UpdateMenuItem(int command_id, - bool enabled, - bool hidden, - const base::string16& title) = 0; - - // Retrieve the given associated objects with a context menu. - virtual content::RenderViewHost* GetRenderViewHost() const = 0; - virtual content::WebContents* GetWebContents() const = 0; - virtual Profile* GetProfile() const = 0; -}; - class RenderViewContextMenu : public ui::SimpleMenuModel::Delegate, public RenderViewContextMenuProxy { public: @@ -166,10 +87,11 @@ class RenderViewContextMenu : public ui::SimpleMenuModel::Delegate, const base::string16& title) OVERRIDE; virtual content::RenderViewHost* GetRenderViewHost() const OVERRIDE; virtual content::WebContents* GetWebContents() const OVERRIDE; - virtual Profile* GetProfile() const OVERRIDE; + virtual content::BrowserContext* GetBrowserContext() const OVERRIDE; protected: void InitMenu(); + Profile* GetProfile(); // Platform specific functions. virtual void PlatformInit() = 0; @@ -184,7 +106,7 @@ class RenderViewContextMenu : public ui::SimpleMenuModel::Delegate, // The RenderFrameHost's IDs. int render_process_id_; int render_frame_id_; - Profile* profile_; + content::BrowserContext* browser_context_; ui::SimpleMenuModel menu_model_; extensions::ContextMenuMatcher extension_items_; diff --git a/chrome/browser/renderer_context_menu/spellchecker_submenu_observer.h b/chrome/browser/renderer_context_menu/spellchecker_submenu_observer.h index af4b233..7d54bae 100644 --- a/chrome/browser/renderer_context_menu/spellchecker_submenu_observer.h +++ b/chrome/browser/renderer_context_menu/spellchecker_submenu_observer.h @@ -10,7 +10,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" -#include "chrome/browser/renderer_context_menu/render_view_context_menu_observer.h" +#include "components/renderer_context_menu/render_view_context_menu_observer.h" #include "ui/base/models/simple_menu_model.h" class RenderViewContextMenuProxy; diff --git a/chrome/browser/renderer_context_menu/spellchecker_submenu_observer_browsertest.cc b/chrome/browser/renderer_context_menu/spellchecker_submenu_observer_browsertest.cc index 495542e..1276da2 100644 --- a/chrome/browser/renderer_context_menu/spellchecker_submenu_observer_browsertest.cc +++ b/chrome/browser/renderer_context_menu/spellchecker_submenu_observer_browsertest.cc @@ -8,10 +8,10 @@ #include "base/strings/utf_string_conversions.h" #include "chrome/app/chrome_command_ids.h" #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" -#include "chrome/browser/renderer_context_menu/render_view_context_menu_observer.h" #include "chrome/common/pref_names.h" #include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/testing_profile.h" +#include "components/renderer_context_menu/render_view_context_menu_observer.h" using content::RenderViewHost; using content::WebContents; @@ -75,7 +75,7 @@ class MockRenderViewContextMenu : public ui::SimpleMenuModel::Delegate, virtual RenderViewHost* GetRenderViewHost() const OVERRIDE { return NULL; } - virtual Profile* GetProfile() const OVERRIDE { + virtual content::BrowserContext* GetBrowserContext() const OVERRIDE { return profile_.get(); } virtual content::WebContents* GetWebContents() const OVERRIDE { diff --git a/chrome/browser/renderer_context_menu/spellchecker_submenu_observer_hunspell.cc b/chrome/browser/renderer_context_menu/spellchecker_submenu_observer_hunspell.cc index 67c6cb6..596c3c9 100644 --- a/chrome/browser/renderer_context_menu/spellchecker_submenu_observer_hunspell.cc +++ b/chrome/browser/renderer_context_menu/spellchecker_submenu_observer_hunspell.cc @@ -43,10 +43,10 @@ void SpellCheckerSubMenuObserver::InitMenu( DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); // Add available spell-checker languages to the sub menu. - Profile* profile = proxy_->GetProfile(); - DCHECK(profile); + content::BrowserContext* browser_context = proxy_->GetBrowserContext(); + DCHECK(browser_context); language_selected_ = - SpellcheckService::GetSpellCheckLanguages(profile, &languages_); + SpellcheckService::GetSpellCheckLanguages(browser_context, &languages_); DCHECK(languages_.size() < IDC_SPELLCHECK_LANGUAGES_LAST - IDC_SPELLCHECK_LANGUAGES_FIRST); const std::string app_locale = g_browser_process->GetApplicationLocale(); @@ -121,7 +121,7 @@ bool SpellCheckerSubMenuObserver::IsCommandIdChecked(int command_id) { // Check box for 'Check Spelling while typing'. if (command_id == IDC_CHECK_SPELLING_WHILE_TYPING) { - Profile* profile = proxy_->GetProfile(); + Profile* profile = Profile::FromBrowserContext(proxy_->GetBrowserContext()); DCHECK(profile); return profile->GetPrefs()->GetBoolean(prefs::kEnableContinuousSpellcheck); } @@ -132,7 +132,7 @@ bool SpellCheckerSubMenuObserver::IsCommandIdChecked(int command_id) { bool SpellCheckerSubMenuObserver::IsCommandIdEnabled(int command_id) { DCHECK(IsCommandIdSupported(command_id)); - Profile* profile = proxy_->GetProfile(); + Profile* profile = Profile::FromBrowserContext(proxy_->GetBrowserContext()); DCHECK(profile); const PrefService* pref = profile->GetPrefs(); if (command_id >= IDC_SPELLCHECK_LANGUAGES_FIRST && @@ -154,7 +154,7 @@ void SpellCheckerSubMenuObserver::ExecuteCommand(int command_id) { DCHECK(IsCommandIdSupported(command_id)); // Check to see if one of the spell check language ids have been clicked. - Profile* profile = proxy_->GetProfile(); + Profile* profile = Profile::FromBrowserContext(proxy_->GetBrowserContext()); DCHECK(profile); if (command_id >= IDC_SPELLCHECK_LANGUAGES_FIRST && command_id < IDC_SPELLCHECK_LANGUAGES_LAST) { diff --git a/chrome/browser/renderer_context_menu/spellchecker_submenu_observer_mac.cc b/chrome/browser/renderer_context_menu/spellchecker_submenu_observer_mac.cc index 97fa3ce..a81e565 100644 --- a/chrome/browser/renderer_context_menu/spellchecker_submenu_observer_mac.cc +++ b/chrome/browser/renderer_context_menu/spellchecker_submenu_observer_mac.cc @@ -13,6 +13,7 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" #include "chrome/common/spellcheck_messages.h" +#include "components/user_prefs/user_prefs.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/render_widget_host_view.h" #include "grit/generated_resources.h" @@ -21,6 +22,14 @@ using content::BrowserThread; +namespace { + +PrefService* GetPrefs(content::BrowserContext* context) { + return user_prefs::UserPrefs::Get(context); +} + +} + SpellCheckerSubMenuObserver::SpellCheckerSubMenuObserver( RenderViewContextMenuProxy* proxy, ui::SimpleMenuModel::Delegate* delegate, @@ -80,9 +89,9 @@ bool SpellCheckerSubMenuObserver::IsCommandIdChecked(int command_id) { // Check box for 'Check Spelling while typing'. if (command_id == IDC_CHECK_SPELLING_WHILE_TYPING) { - Profile* profile = proxy_->GetProfile(); - DCHECK(profile); - return profile->GetPrefs()->GetBoolean(prefs::kEnableContinuousSpellcheck); + content::BrowserContext* context = proxy_->GetBrowserContext(); + DCHECK(context); + return GetPrefs(context)->GetBoolean(prefs::kEnableContinuousSpellcheck); } return false; @@ -106,13 +115,13 @@ void SpellCheckerSubMenuObserver::ExecuteCommand(int command_id) { DCHECK(IsCommandIdSupported(command_id)); content::RenderViewHost* rvh = proxy_->GetRenderViewHost(); - Profile* profile = proxy_->GetProfile(); - DCHECK(profile); + content::BrowserContext* context = proxy_->GetBrowserContext(); + DCHECK(context); switch (command_id) { case IDC_CHECK_SPELLING_WHILE_TYPING: - profile->GetPrefs()->SetBoolean( + GetPrefs(context)->SetBoolean( prefs::kEnableContinuousSpellcheck, - !profile->GetPrefs()->GetBoolean(prefs::kEnableContinuousSpellcheck)); + !GetPrefs(context)->GetBoolean(prefs::kEnableContinuousSpellcheck)); break; case IDC_SPELLPANEL_TOGGLE: diff --git a/chrome/browser/renderer_context_menu/spelling_menu_observer.cc b/chrome/browser/renderer_context_menu/spelling_menu_observer.cc index aed1920..b397709 100644 --- a/chrome/browser/renderer_context_menu/spelling_menu_observer.cc +++ b/chrome/browser/renderer_context_menu/spelling_menu_observer.cc @@ -39,11 +39,12 @@ SpellingMenuObserver::SpellingMenuObserver(RenderViewContextMenuProxy* proxy) succeeded_(false), misspelling_hash_(0), client_(new SpellingServiceClient) { - if (proxy && proxy->GetProfile()) { + if (proxy_ && proxy_->GetBrowserContext()) { + Profile* profile = Profile::FromBrowserContext(proxy_->GetBrowserContext()); integrate_spelling_service_.Init(prefs::kSpellCheckUseSpellingService, - proxy->GetProfile()->GetPrefs()); + profile->GetPrefs()); autocorrect_spelling_.Init(prefs::kEnableAutoSpellCorrect, - proxy->GetProfile()->GetPrefs()); + profile->GetPrefs()); } } @@ -57,8 +58,8 @@ void SpellingMenuObserver::InitMenu(const content::ContextMenuParams& params) { // Exit if we are not in an editable element because we add a menu item only // for editable elements. - Profile* profile = proxy_->GetProfile(); - if (!params.is_editable || !profile) + content::BrowserContext* browser_context = proxy_->GetBrowserContext(); + if (!params.is_editable || !browser_context) return; // Exit if there is no misspelled word. @@ -70,7 +71,7 @@ void SpellingMenuObserver::InitMenu(const content::ContextMenuParams& params) { misspelling_hash_ = params.misspelling_hash; bool use_suggestions = SpellingServiceClient::IsAvailable( - profile, SpellingServiceClient::SUGGEST); + browser_context, SpellingServiceClient::SUGGEST); if (!suggestions_.empty() || use_suggestions) proxy_->AddSeparator(); @@ -130,9 +131,12 @@ void SpellingMenuObserver::InitMenu(const content::ContextMenuParams& params) { // starts the animation timer so we can show animation until we receive // it. bool result = client_->RequestTextCheck( - profile, SpellingServiceClient::SUGGEST, params.misspelled_word, + browser_context, + SpellingServiceClient::SUGGEST, + params.misspelled_word, base::Bind(&SpellingMenuObserver::OnTextCheckComplete, - base::Unretained(this), SpellingServiceClient::SUGGEST)); + base::Unretained(this), + SpellingServiceClient::SUGGEST)); if (result) { loading_frame_ = 0; animation_timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(1), @@ -145,7 +149,7 @@ void SpellingMenuObserver::InitMenu(const content::ContextMenuParams& params) { IDC_CONTENT_CONTEXT_NO_SPELLING_SUGGESTIONS, l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_NO_SPELLING_SUGGESTIONS)); bool use_spelling_service = SpellingServiceClient::IsAvailable( - profile, SpellingServiceClient::SPELLCHECK); + browser_context, SpellingServiceClient::SPELLCHECK); if (use_suggestions || use_spelling_service) proxy_->AddSeparator(); } else { @@ -154,7 +158,7 @@ void SpellingMenuObserver::InitMenu(const content::ContextMenuParams& params) { // |spellcheck_service| can be null when the suggested word is // provided by Web SpellCheck API. SpellcheckService* spellcheck_service = - SpellcheckServiceFactory::GetForContext(profile); + SpellcheckServiceFactory::GetForContext(browser_context); if (spellcheck_service && spellcheck_service->GetMetrics()) spellcheck_service->GetMetrics()->RecordSuggestionStats(1); } @@ -196,13 +200,12 @@ bool SpellingMenuObserver::IsCommandIdSupported(int command_id) { bool SpellingMenuObserver::IsCommandIdChecked(int command_id) { DCHECK(IsCommandIdSupported(command_id)); + Profile* profile = Profile::FromBrowserContext(proxy_->GetBrowserContext()); if (command_id == IDC_CONTENT_CONTEXT_SPELLING_TOGGLE) - return integrate_spelling_service_.GetValue() && - !proxy_->GetProfile()->IsOffTheRecord(); + return integrate_spelling_service_.GetValue() && !profile->IsOffTheRecord(); if (command_id == IDC_CONTENT_CONTEXT_AUTOCORRECT_SPELLING_TOGGLE) - return autocorrect_spelling_.GetValue() && - !proxy_->GetProfile()->IsOffTheRecord(); + return autocorrect_spelling_.GetValue() && !profile->IsOffTheRecord(); return false; } @@ -213,6 +216,7 @@ bool SpellingMenuObserver::IsCommandIdEnabled(int command_id) { command_id <= IDC_SPELLCHECK_SUGGESTION_LAST) return true; + Profile* profile = Profile::FromBrowserContext(proxy_->GetBrowserContext()); switch (command_id) { case IDC_SPELLCHECK_ADD_TO_DICTIONARY: return !misspelled_word_.empty(); @@ -225,11 +229,11 @@ bool SpellingMenuObserver::IsCommandIdEnabled(int command_id) { case IDC_CONTENT_CONTEXT_SPELLING_TOGGLE: return integrate_spelling_service_.IsUserModifiable() && - !proxy_->GetProfile()->IsOffTheRecord(); + !profile->IsOffTheRecord(); case IDC_CONTENT_CONTEXT_AUTOCORRECT_SPELLING_TOGGLE: return integrate_spelling_service_.IsUserModifiable() && - !proxy_->GetProfile()->IsOffTheRecord(); + !profile->IsOffTheRecord(); default: return false; @@ -246,10 +250,10 @@ void SpellingMenuObserver::ExecuteCommand(int command_id) { suggestions_[suggestion_index]); // GetSpellCheckHost() can return null when the suggested word is provided // by Web SpellCheck API. - Profile* profile = proxy_->GetProfile(); - if (profile) { + content::BrowserContext* browser_context = proxy_->GetBrowserContext(); + if (browser_context) { SpellcheckService* spellcheck = - SpellcheckServiceFactory::GetForContext(profile); + SpellcheckServiceFactory::GetForContext(browser_context); if (spellcheck) { if (spellcheck->GetMetrics()) spellcheck->GetMetrics()->RecordReplacedWordStats(1); @@ -272,10 +276,10 @@ void SpellingMenuObserver::ExecuteCommand(int command_id) { command_id == IDC_SPELLCHECK_ADD_TO_DICTIONARY) { // GetHostForProfile() can return null when the suggested word is provided // by Web SpellCheck API. - Profile* profile = proxy_->GetProfile(); - if (profile) { + content::BrowserContext* browser_context = proxy_->GetBrowserContext(); + if (browser_context) { SpellcheckService* spellcheck = - SpellcheckServiceFactory::GetForContext(profile); + SpellcheckServiceFactory::GetForContext(browser_context); if (spellcheck) { spellcheck->GetCustomDictionary()->AddWord(base::UTF16ToUTF8( misspelled_word_)); @@ -287,6 +291,8 @@ void SpellingMenuObserver::ExecuteCommand(int command_id) { #endif } + Profile* profile = Profile::FromBrowserContext(proxy_->GetBrowserContext()); + // The spelling service can be toggled by the user only if it is not managed. if (command_id == IDC_CONTENT_CONTEXT_SPELLING_TOGGLE && integrate_spelling_service_.IsUserModifiable()) { @@ -301,11 +307,8 @@ void SpellingMenuObserver::ExecuteCommand(int command_id) { proxy_->GetWebContents()->GetTopLevelNativeWindow(), rvh->GetView()->GetNativeView(), gfx::Point(rect.CenterPoint().x(), rect.y()), - new SpellingBubbleModel(proxy_->GetProfile(), - proxy_->GetWebContents(), - false)); + new SpellingBubbleModel(profile, proxy_->GetWebContents(), false)); } else { - Profile* profile = proxy_->GetProfile(); if (profile) { profile->GetPrefs()->SetBoolean(prefs::kSpellCheckUseSpellingService, false); @@ -328,11 +331,8 @@ void SpellingMenuObserver::ExecuteCommand(int command_id) { proxy_->GetWebContents()->GetTopLevelNativeWindow(), rvh->GetView()->GetNativeView(), gfx::Point(rect.CenterPoint().x(), rect.y()), - new SpellingBubbleModel(proxy_->GetProfile(), - proxy_->GetWebContents(), - true)); + new SpellingBubbleModel(profile, proxy_->GetWebContents(), true)); } else { - Profile* profile = proxy_->GetProfile(); if (profile) { bool current_value = autocorrect_spelling_.GetValue(); profile->GetPrefs()->SetBoolean(prefs::kEnableAutoSpellCorrect, @@ -343,11 +343,11 @@ void SpellingMenuObserver::ExecuteCommand(int command_id) { } void SpellingMenuObserver::OnMenuCancel() { - Profile* profile = proxy_->GetProfile(); - if (!profile) + content::BrowserContext* browser_context = proxy_->GetBrowserContext(); + if (!browser_context) return; SpellcheckService* spellcheck = - SpellcheckServiceFactory::GetForContext(profile); + SpellcheckServiceFactory::GetForContext(browser_context); if (!spellcheck) return; spellcheck->GetFeedbackSender()->IgnoredSuggestions(misspelling_hash_); diff --git a/chrome/browser/renderer_context_menu/spelling_menu_observer.h b/chrome/browser/renderer_context_menu/spelling_menu_observer.h index aa482d8..d20afdd 100644 --- a/chrome/browser/renderer_context_menu/spelling_menu_observer.h +++ b/chrome/browser/renderer_context_menu/spelling_menu_observer.h @@ -12,8 +12,8 @@ #include "base/prefs/pref_member.h" #include "base/strings/string16.h" #include "base/timer/timer.h" -#include "chrome/browser/renderer_context_menu/render_view_context_menu_observer.h" #include "chrome/browser/spellchecker/spelling_service_client.h" +#include "components/renderer_context_menu/render_view_context_menu_observer.h" class RenderViewContextMenuProxy; struct SpellCheckResult; diff --git a/chrome/browser/renderer_context_menu/spelling_menu_observer_browsertest.cc b/chrome/browser/renderer_context_menu/spelling_menu_observer_browsertest.cc index 3d281ce..943d689 100644 --- a/chrome/browser/renderer_context_menu/spelling_menu_observer_browsertest.cc +++ b/chrome/browser/renderer_context_menu/spelling_menu_observer_browsertest.cc @@ -10,11 +10,11 @@ #include "base/strings/utf_string_conversions.h" #include "chrome/app/chrome_command_ids.h" #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" -#include "chrome/browser/renderer_context_menu/render_view_context_menu_observer.h" #include "chrome/browser/spellchecker/spelling_service_client.h" #include "chrome/common/pref_names.h" #include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/testing_profile.h" +#include "components/renderer_context_menu/render_view_context_menu_observer.h" using content::RenderViewHost; using content::WebContents; @@ -60,7 +60,7 @@ class MockRenderViewContextMenu : public RenderViewContextMenuProxy { const base::string16& title) OVERRIDE; virtual RenderViewHost* GetRenderViewHost() const OVERRIDE; virtual WebContents* GetWebContents() const OVERRIDE; - virtual Profile* GetProfile() const OVERRIDE; + virtual content::BrowserContext* GetBrowserContext() const OVERRIDE; // Attaches a RenderViewContextMenuObserver to be tested. void SetObserver(RenderViewContextMenuObserver* observer); @@ -169,7 +169,7 @@ WebContents* MockRenderViewContextMenu::GetWebContents() const { return NULL; } -Profile* MockRenderViewContextMenu::GetProfile() const { +content::BrowserContext* MockRenderViewContextMenu::GetBrowserContext() const { return profile_.get(); } @@ -235,9 +235,9 @@ class SpellingMenuObserverTest : public InProcessBrowserTest { // Force a non-empty and non-"en" locale so SUGGEST is available. menu()->GetPrefs()->SetString(prefs::kSpellCheckDictionary, "fr"); ASSERT_TRUE(SpellingServiceClient::IsAvailable( - menu()->GetProfile(), SpellingServiceClient::SUGGEST)); + menu()->GetBrowserContext(), SpellingServiceClient::SUGGEST)); ASSERT_FALSE(SpellingServiceClient::IsAvailable( - menu()->GetProfile(), SpellingServiceClient::SPELLCHECK)); + menu()->GetBrowserContext(), SpellingServiceClient::SPELLCHECK)); } virtual ~SpellingMenuObserverTest(); @@ -369,8 +369,8 @@ IN_PROC_BROWSER_TEST_F(SpellingMenuObserverTest, // Force a non-empty locale so SPELLCHECK is available. menu()->GetPrefs()->SetString(prefs::kSpellCheckDictionary, "en"); - EXPECT_TRUE(SpellingServiceClient::IsAvailable(menu()->GetProfile(), - SpellingServiceClient::SPELLCHECK)); + EXPECT_TRUE(SpellingServiceClient::IsAvailable( + menu()->GetBrowserContext(), SpellingServiceClient::SPELLCHECK)); InitMenu("asdfkj", "asdf"); // The test should see a separator, a suggestion and another separator @@ -410,10 +410,10 @@ IN_PROC_BROWSER_TEST_F(SpellingMenuObserverTest, // Force a non-empty locale so SUGGEST normally would be available. menu()->GetPrefs()->SetString(prefs::kSpellCheckDictionary, "en"); - EXPECT_FALSE(SpellingServiceClient::IsAvailable(menu()->GetProfile(), - SpellingServiceClient::SUGGEST)); - EXPECT_FALSE(SpellingServiceClient::IsAvailable(menu()->GetProfile(), - SpellingServiceClient::SPELLCHECK)); + EXPECT_FALSE(SpellingServiceClient::IsAvailable( + menu()->GetBrowserContext(), SpellingServiceClient::SUGGEST)); + EXPECT_FALSE(SpellingServiceClient::IsAvailable( + menu()->GetBrowserContext(), SpellingServiceClient::SPELLCHECK)); InitMenu("sjxdjiiiiii", NULL); diff --git a/chrome/browser/ui/cocoa/tab_contents/chrome_web_contents_view_delegate_mac.h b/chrome/browser/ui/cocoa/tab_contents/chrome_web_contents_view_delegate_mac.h index 85c2551..ba128a3 100644 --- a/chrome/browser/ui/cocoa/tab_contents/chrome_web_contents_view_delegate_mac.h +++ b/chrome/browser/ui/cocoa/tab_contents/chrome_web_contents_view_delegate_mac.h @@ -9,7 +9,7 @@ #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" -#include "chrome/browser/renderer_context_menu/context_menu_delegate.h" +#include "components/renderer_context_menu/context_menu_delegate.h" #include "content/public/browser/web_contents_view_delegate.h" class RenderViewContextMenu; diff --git a/chrome/browser/ui/views/tab_contents/chrome_web_contents_view_delegate_views.h b/chrome/browser/ui/views/tab_contents/chrome_web_contents_view_delegate_views.h index 09f2231..b7170b3 100644 --- a/chrome/browser/ui/views/tab_contents/chrome_web_contents_view_delegate_views.h +++ b/chrome/browser/ui/views/tab_contents/chrome_web_contents_view_delegate_views.h @@ -8,7 +8,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" -#include "chrome/browser/renderer_context_menu/context_menu_delegate.h" +#include "components/renderer_context_menu/context_menu_delegate.h" #include "content/public/browser/web_contents_view_delegate.h" class RenderViewContextMenu; diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 2b995bf..280e9277 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1106,8 +1106,6 @@ 'browser/renderer_context_menu/context_menu_content_type_panel.h', 'browser/renderer_context_menu/context_menu_content_type_platform_app.cc', 'browser/renderer_context_menu/context_menu_content_type_platform_app.h', - 'browser/renderer_context_menu/context_menu_delegate.cc', - 'browser/renderer_context_menu/context_menu_delegate.h', 'browser/renderer_context_menu/spellchecker_submenu_observer.h', 'browser/renderer_context_menu/spellchecker_submenu_observer_mac.cc', 'browser/renderer_host/chrome_render_message_filter.cc', @@ -2212,8 +2210,6 @@ 'browser/profiles/profile_shortcut_manager.h', 'browser/renderer_context_menu/render_view_context_menu.cc', 'browser/renderer_context_menu/render_view_context_menu.h', - 'browser/renderer_context_menu/render_view_context_menu_observer.cc', - 'browser/renderer_context_menu/render_view_context_menu_observer.h', 'browser/renderer_context_menu/spelling_bubble_model.cc', 'browser/renderer_context_menu/spelling_bubble_model.h', 'browser/renderer_context_menu/spelling_menu_observer.cc', @@ -2885,6 +2881,7 @@ '../components/components.gyp:precache_core', '../components/components.gyp:query_parser', '../components/components.gyp:rappor', + '../components/components.gyp:renderer_context_menu', '../components/components.gyp:search', '../components/components.gyp:search_engines', '../components/components.gyp:search_provider_logos', diff --git a/components/OWNERS b/components/OWNERS index 48cd62d..e721131 100644 --- a/components/OWNERS +++ b/components/OWNERS @@ -137,6 +137,10 @@ per-file query_parser.gypi=sky@chromium.org per-file rappor*=asvitkine@chromium.org # OWNER-to-be: per-file rappor*=holte@chromium.org +per-file renderer_context_menu*=avi@chromium.org +per-file renderer_context_menu*=brettw@chromium.org +per-file renderer_context_menu*=lazyboy@chromium.org + per-file search.gypi=kmadhusu@chromium.org per-file search.gypi=brettw@chromium.org per-file search.gypi=jered@chromium.org diff --git a/components/components.gyp b/components/components.gyp index c14de82..a62fa88 100644 --- a/components/components.gyp +++ b/components/components.gyp @@ -45,6 +45,7 @@ 'pref_registry.gypi', 'query_parser.gypi', 'rappor.gypi', + 'renderer_context_menu.gypi', 'search.gypi', 'search_provider_logos.gypi', 'signin.gypi', diff --git a/components/renderer_context_menu.gypi b/components/renderer_context_menu.gypi new file mode 100644 index 0000000..64efd85 --- /dev/null +++ b/components/renderer_context_menu.gypi @@ -0,0 +1,25 @@ +# Copyright 2014 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. +{ + 'targets': [ + { + 'target_name': 'renderer_context_menu', + 'type': 'static_library', + 'dependencies': [ + '../base/base.gyp:base', + '../content/content.gyp:content_browser', + ], + 'include_dirs': [ + '..', + ], + 'sources': [ + 'renderer_context_menu/context_menu_delegate.cc', + 'renderer_context_menu/context_menu_delegate.h', + 'renderer_context_menu/render_view_context_menu_observer.cc', + 'renderer_context_menu/render_view_context_menu_observer.h', + 'renderer_context_menu/render_view_context_menu_proxy.h', + ], + }, + ], +} diff --git a/components/renderer_context_menu/DEPS b/components/renderer_context_menu/DEPS new file mode 100644 index 0000000..1c35d9c --- /dev/null +++ b/components/renderer_context_menu/DEPS @@ -0,0 +1,3 @@ +include_rules = [ + "+content/public/browser", +] diff --git a/chrome/browser/renderer_context_menu/context_menu_delegate.cc b/components/renderer_context_menu/context_menu_delegate.cc index 4a03b41..c6129b8 100644 --- a/chrome/browser/renderer_context_menu/context_menu_delegate.cc +++ b/components/renderer_context_menu/context_menu_delegate.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/renderer_context_menu/context_menu_delegate.h" +#include "components/renderer_context_menu/context_menu_delegate.h" #include "content/public/browser/web_contents.h" @@ -13,8 +13,7 @@ const char kMenuDelegateUserDataKey[] = "RendererContextMenuMenuDelegate"; class ContextMenuDelegateUserData : public base::SupportsUserData::Data { public: explicit ContextMenuDelegateUserData(ContextMenuDelegate* menu_delegate) - : menu_delegate_(menu_delegate) { - } + : menu_delegate_(menu_delegate) {} virtual ~ContextMenuDelegateUserData() {} ContextMenuDelegate* menu_delegate() { return menu_delegate_; } diff --git a/chrome/browser/renderer_context_menu/context_menu_delegate.h b/components/renderer_context_menu/context_menu_delegate.h index b6a8255..57327b1 100644 --- a/chrome/browser/renderer_context_menu/context_menu_delegate.h +++ b/components/renderer_context_menu/context_menu_delegate.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_RENDERER_CONTEXT_MENU_CONTEXT_MENU_DELEGATE_H_ -#define CHROME_BROWSER_RENDERER_CONTEXT_MENU_CONTEXT_MENU_DELEGATE_H_ +#ifndef COMPONENTS_RENDERER_CONTEXT_MENU_CONTEXT_MENU_DELEGATE_H_ +#define COMPONENTS_RENDERER_CONTEXT_MENU_CONTEXT_MENU_DELEGATE_H_ #include "base/memory/scoped_ptr.h" @@ -36,4 +36,4 @@ class ContextMenuDelegate { DISALLOW_COPY_AND_ASSIGN(ContextMenuDelegate); }; -#endif // CHROME_BROWSER_RENDERER_CONTEXT_MENU_CONTEXT_MENU_DELEGATE_H_ +#endif // COMPONENTS_RENDERER_CONTEXT_MENU_CONTEXT_MENU_DELEGATE_H_ diff --git a/chrome/browser/renderer_context_menu/render_view_context_menu_observer.cc b/components/renderer_context_menu/render_view_context_menu_observer.cc index 7003aa7..2e2d05f9 100644 --- a/chrome/browser/renderer_context_menu/render_view_context_menu_observer.cc +++ b/components/renderer_context_menu/render_view_context_menu_observer.cc @@ -2,11 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/renderer_context_menu/render_view_context_menu_observer.h" - -void RenderViewContextMenuObserver::InitMenu( - const content::ContextMenuParams& params) { -} +#include "components/renderer_context_menu/render_view_context_menu_observer.h" bool RenderViewContextMenuObserver::IsCommandIdSupported(int command_id) { return false; @@ -19,9 +15,3 @@ bool RenderViewContextMenuObserver::IsCommandIdChecked(int command_id) { bool RenderViewContextMenuObserver::IsCommandIdEnabled(int command_id) { return false; } - -void RenderViewContextMenuObserver::ExecuteCommand(int command_id) { -} - -void RenderViewContextMenuObserver::OnMenuCancel() { -} diff --git a/chrome/browser/renderer_context_menu/render_view_context_menu_observer.h b/components/renderer_context_menu/render_view_context_menu_observer.h index c9d7130..7fbca52 100644 --- a/chrome/browser/renderer_context_menu/render_view_context_menu_observer.h +++ b/components/renderer_context_menu/render_view_context_menu_observer.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_OBSERVER_H_ -#define CHROME_BROWSER_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_OBSERVER_H_ +#ifndef COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_OBSERVER_H_ +#define COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_OBSERVER_H_ namespace content { struct ContextMenuParams; @@ -84,7 +84,7 @@ class RenderViewContextMenuObserver { // Called when the RenderViewContextMenu class initializes a context menu. We // usually call RenderViewContextMenuDelegate::AddMenuItem() to add menu items // in this function. - virtual void InitMenu(const content::ContextMenuParams& params); + virtual void InitMenu(const content::ContextMenuParams& params) {} // Called when the RenderViewContextMenu class asks whether an observer // listens for the specified command ID. If this function returns true, the @@ -98,10 +98,10 @@ class RenderViewContextMenuObserver { virtual bool IsCommandIdEnabled(int command_id); // Called when a user selects the specified context-menu item. - virtual void ExecuteCommand(int command_id); + virtual void ExecuteCommand(int command_id) {} // Called when a user closes the context menu without selecting any items. - virtual void OnMenuCancel(); + virtual void OnMenuCancel() {} }; -#endif // CHROME_BROWSER_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_OBSERVER_H_ +#endif // COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_OBSERVER_H_ diff --git a/components/renderer_context_menu/render_view_context_menu_proxy.h b/components/renderer_context_menu/render_view_context_menu_proxy.h new file mode 100644 index 0000000..789b149 --- /dev/null +++ b/components/renderer_context_menu/render_view_context_menu_proxy.h @@ -0,0 +1,95 @@ +// Copyright 2014 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 COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_PROXY_H_ +#define COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_PROXY_H_ + +#include "base/strings/string16.h" + +namespace content { +class BrowserContext; +class RenderViewHost; +class WebContents; +} + +// An interface that controls a RenderViewContextMenu instance from observers. +// This interface is designed mainly for controlling the instance while showing +// so we can add a context-menu item that takes long time to create its text, +// such as retrieving the item text from a server. The simplest usage is: +// 1. Adding an item with temporary text; +// 2. Posting a background task that creates the item text, and; +// 3. Calling UpdateMenuItem() in the callback function. +// The following snippet describes the simple usage that updates a context-menu +// item with this interface. +// +// class MyTask : public net::URLFetcherDelegate { +// public: +// MyTask(RenderViewContextMenuProxy* proxy, int id) +// : proxy_(proxy), +// id_(id) { +// } +// virtual ~MyTask() { +// } +// virtual void OnURLFetchComplete(const net::URLFetcher* source, +// const GURL& url, +// const net::URLRequestStatus& status, +// int response, +// const net::ResponseCookies& cookies, +// const std::string& data) { +// bool enabled = response == 200; +// const char* text = enabled ? "OK" : "ERROR"; +// proxy_->UpdateMenuItem(id_, enabled, base::ASCIIToUTF16(text)); +// } +// void Start(const GURL* url, net::URLRequestContextGetter* context) { +// fetcher_.reset(new URLFetcher(url, URLFetcher::GET, this)); +// fetcher_->SetRequestContext(context); +// content::AssociateURLFetcherWithRenderView( +// fetcher_.get(), +// proxy_->GetRenderViewHost()->GetSiteInstance()->GetSite(), +// proxy_->GetRenderViewHost()->GetProcess()->GetID(), +// proxy_->GetRenderViewHost()->GetRoutingID()); +// fetcher_->Start(); +// } +// +// private: +// URLFetcher fetcher_; +// RenderViewContextMenuProxy* proxy_; +// int id_; +// }; +// +// void RenderViewContextMenu::AppendEditableItems() { +// // Add a menu item with temporary text shown while we create the final +// // text. +// menu_model_.AddItemWithStringId(IDC_MY_ITEM, IDC_MY_TEXT); +// +// // Start a task that creates the final text. +// my_task_ = new MyTask(this, IDC_MY_ITEM); +// my_task_->Start(...); +// } +// +class RenderViewContextMenuProxy { + public: + // Add a menu item to a context menu. + virtual void AddMenuItem(int command_id, const base::string16& title) = 0; + virtual void AddCheckItem(int command_id, const base::string16& title) = 0; + virtual void AddSeparator() = 0; + + // Add a submenu item to a context menu. + virtual void AddSubMenu(int command_id, + const base::string16& label, + ui::MenuModel* model) = 0; + + // Update the status and text of the specified context-menu item. + virtual void UpdateMenuItem(int command_id, + bool enabled, + bool hidden, + const base::string16& title) = 0; + + // Retrieve the given associated objects with a context menu. + virtual content::RenderViewHost* GetRenderViewHost() const = 0; + virtual content::WebContents* GetWebContents() const = 0; + virtual content::BrowserContext* GetBrowserContext() const = 0; +}; + +#endif // COMPONENTS_RENDERER_CONTEXT_MENU_RENDER_VIEW_CONTEXT_MENU_PROXY_H_ |