diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-23 02:00:01 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-07-23 02:00:01 +0000 |
commit | 3c71576ce539b9c8e2480e1a257dca945391c40a (patch) | |
tree | 2e2581cebbf92059d6ccc6dc51b83746c934976a /chrome/browser/ui | |
parent | c5072ad5f9c23f8509db857e974f936bafe0a693 (diff) | |
download | chromium_src-3c71576ce539b9c8e2480e1a257dca945391c40a.zip chromium_src-3c71576ce539b9c8e2480e1a257dca945391c40a.tar.gz chromium_src-3c71576ce539b9c8e2480e1a257dca945391c40a.tar.bz2 |
Hide knowledge of webkit::ppapi::PluginDelegate from chrome. This is part of moving ppapi implementation from webkit/plugins/ppapi to content/renderer.
Chrome used four methods on that interface for PDFs.
-DidStartLoading/DidStopLoading: I just exposed these methods from RenderViewImpl on the RenderView interface
-SetContentRestriction: I moved this functionality completely into chrome. This allows us to get rid of all the content restrictions related methods in the content API, and to move content_restriction.h out to chrome.
-SaveURLAs: exposed the internal SaveURL method on WebContents
BUG=263054
R=scottmg@chromium.org
Review URL: https://codereview.chromium.org/19800005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@213027 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui')
-rw-r--r-- | chrome/browser/ui/browser.cc | 5 | ||||
-rw-r--r-- | chrome/browser/ui/browser.h | 2 | ||||
-rw-r--r-- | chrome/browser/ui/browser_command_controller.cc | 8 | ||||
-rw-r--r-- | chrome/browser/ui/browser_commands.cc | 15 | ||||
-rw-r--r-- | chrome/browser/ui/pdf/pdf_tab_helper.cc | 21 | ||||
-rw-r--r-- | chrome/browser/ui/pdf/pdf_tab_helper.h | 5 | ||||
-rw-r--r-- | chrome/browser/ui/tab_contents/core_tab_helper.cc | 21 | ||||
-rw-r--r-- | chrome/browser/ui/tab_contents/core_tab_helper.h | 9 |
8 files changed, 65 insertions, 21 deletions
diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index 31374d5..bd0799f 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -166,7 +166,6 @@ #include "content/public/browser/user_metrics.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_view.h" -#include "content/public/common/content_restriction.h" #include "content/public/common/content_switches.h" #include "content/public/common/page_zoom.h" #include "content/public/common/renderer_preferences.h" @@ -1543,10 +1542,6 @@ void Browser::WebContentsCreated(WebContents* source_contents, content::Details<RetargetingDetails>(&details)); } -void Browser::ContentRestrictionsChanged(WebContents* source) { - command_controller_->ContentRestrictionsChanged(); -} - void Browser::RendererUnresponsive(WebContents* source) { // Ignore hangs if a tab is blocked. int index = tab_strip_model_->GetIndexOfWebContents(source); diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h index af74dbb..61be1dd 100644 --- a/chrome/browser/ui/browser.h +++ b/chrome/browser/ui/browser.h @@ -573,8 +573,6 @@ class Browser : public TabStripModelObserver, const string16& frame_name, const GURL& target_url, content::WebContents* new_contents) OVERRIDE; - virtual void ContentRestrictionsChanged( - content::WebContents* source) OVERRIDE; virtual void RendererUnresponsive(content::WebContents* source) OVERRIDE; virtual void RendererResponsive(content::WebContents* source) OVERRIDE; virtual void WorkerCrashed(content::WebContents* source) OVERRIDE; diff --git a/chrome/browser/ui/browser_command_controller.cc b/chrome/browser/ui/browser_command_controller.cc index 54b8ecc..8726534 100644 --- a/chrome/browser/ui/browser_command_controller.cc +++ b/chrome/browser/ui/browser_command_controller.cc @@ -27,6 +27,7 @@ #include "chrome/browser/ui/sync/sync_promo_ui.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model_utils.h" +#include "chrome/common/content_restriction.h" #include "chrome/common/pref_names.h" #include "chrome/common/profiling.h" #include "content/public/browser/native_web_keyboard_event.h" @@ -35,7 +36,6 @@ #include "content/public/browser/user_metrics.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_observer.h" -#include "content/public/common/content_restriction.h" #include "content/public/common/url_constants.h" #include "ui/base/keycodes/keyboard_codes.h" @@ -1042,11 +1042,11 @@ void BrowserCommandController::UpdateCommandsForContentRestrictionState() { int restrictions = GetContentRestrictions(browser_); command_updater_.UpdateCommandEnabled( - IDC_COPY, !(restrictions & content::CONTENT_RESTRICTION_COPY)); + IDC_COPY, !(restrictions & CONTENT_RESTRICTION_COPY)); command_updater_.UpdateCommandEnabled( - IDC_CUT, !(restrictions & content::CONTENT_RESTRICTION_CUT)); + IDC_CUT, !(restrictions & CONTENT_RESTRICTION_CUT)); command_updater_.UpdateCommandEnabled( - IDC_PASTE, !(restrictions & content::CONTENT_RESTRICTION_PASTE)); + IDC_PASTE, !(restrictions & CONTENT_RESTRICTION_PASTE)); UpdateSaveAsState(); UpdatePrintingState(); } diff --git a/chrome/browser/ui/browser_commands.cc b/chrome/browser/ui/browser_commands.cc index 22f6e1c..c083fba 100644 --- a/chrome/browser/ui/browser_commands.cc +++ b/chrome/browser/ui/browser_commands.cc @@ -50,12 +50,14 @@ #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" #include "chrome/browser/ui/omnibox/location_bar.h" #include "chrome/browser/ui/status_bubble.h" +#include "chrome/browser/ui/tab_contents/core_tab_helper.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" #include "chrome/browser/upgrade_detector.h" #include "chrome/browser/web_applications/web_app.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_version_info.h" +#include "chrome/common/content_restriction.h" #include "chrome/common/pref_names.h" #include "components/web_modal/web_contents_modal_dialog_manager.h" #include "content/public/browser/devtools_agent_host.h" @@ -67,7 +69,6 @@ #include "content/public/browser/user_metrics.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents_view.h" -#include "content/public/common/content_restriction.h" #include "content/public/common/renderer_preferences.h" #include "content/public/common/url_constants.h" #include "content/public/common/url_utils.h" @@ -242,16 +243,18 @@ int GetContentRestrictions(const Browser* browser) { int content_restrictions = 0; WebContents* current_tab = browser->tab_strip_model()->GetActiveWebContents(); if (current_tab) { - content_restrictions = current_tab->GetContentRestrictions(); + CoreTabHelper* core_tab_helper = + CoreTabHelper::FromWebContents(current_tab); + content_restrictions = core_tab_helper->content_restrictions(); NavigationEntry* active_entry = current_tab->GetController().GetActiveEntry(); // See comment in UpdateCommandsForTabState about why we call url(). if (!content::IsSavableURL( active_entry ? active_entry->GetURL() : GURL()) || current_tab->ShowingInterstitialPage()) - content_restrictions |= content::CONTENT_RESTRICTION_SAVE; + content_restrictions |= CONTENT_RESTRICTION_SAVE; if (current_tab->ShowingInterstitialPage()) - content_restrictions |= content::CONTENT_RESTRICTION_PRINT; + content_restrictions |= CONTENT_RESTRICTION_PRINT; } return content_restrictions; } @@ -694,7 +697,7 @@ bool CanSavePage(const Browser* browser) { return false; } return !browser->is_devtools() && - !(GetContentRestrictions(browser) & content::CONTENT_RESTRICTION_SAVE); + !(GetContentRestrictions(browser) & CONTENT_RESTRICTION_SAVE); } void ShowFindBar(Browser* browser) { @@ -726,7 +729,7 @@ bool CanPrint(const Browser* browser) { // Do not print when a constrained window is showing. It's confusing. return browser->profile()->GetPrefs()->GetBoolean(prefs::kPrintingEnabled) && !(IsShowingWebContentsModalDialog(browser) || - GetContentRestrictions(browser) & content::CONTENT_RESTRICTION_PRINT); + GetContentRestrictions(browser) & CONTENT_RESTRICTION_PRINT); } void AdvancedPrint(Browser* browser) { diff --git a/chrome/browser/ui/pdf/pdf_tab_helper.cc b/chrome/browser/ui/pdf/pdf_tab_helper.cc index 3e3bfcb..d78bb81 100644 --- a/chrome/browser/ui/pdf/pdf_tab_helper.cc +++ b/chrome/browser/ui/pdf/pdf_tab_helper.cc @@ -4,12 +4,14 @@ #include "chrome/browser/ui/pdf/pdf_tab_helper.h" +#include "chrome/browser/download/download_util.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/omnibox/location_bar.h" #include "chrome/browser/ui/pdf/open_pdf_in_reader_prompt_delegate.h" #include "chrome/browser/ui/pdf/pdf_unsupported_feature.h" +#include "chrome/browser/ui/tab_contents/core_tab_helper.h" #include "chrome/common/render_messages.h" #include "content/public/browser/navigation_details.h" @@ -32,7 +34,10 @@ bool PDFTabHelper::OnMessageReceived(const IPC::Message& message) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(PDFTabHelper, message) IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PDFHasUnsupportedFeature, - OnPDFHasUnsupportedFeature) + OnHasUnsupportedFeature) + IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PDFSaveURLAs, OnSaveURLAs) + IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PDFUpdateContentRestrictions, + OnUpdateContentRestrictions) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() return handled; @@ -64,6 +69,18 @@ void PDFTabHelper::UpdateLocationBar() { location_bar->UpdateOpenPDFInReaderPrompt(); } -void PDFTabHelper::OnPDFHasUnsupportedFeature() { +void PDFTabHelper::OnHasUnsupportedFeature() { PDFHasUnsupportedFeature(web_contents()); } + +void PDFTabHelper::OnSaveURLAs(const GURL& url, + const content::Referrer& referrer) { + download_util::RecordDownloadSource(download_util::INITIATED_BY_PDF_SAVE); + web_contents()->SaveFrame(url, referrer); +} + +void PDFTabHelper::OnUpdateContentRestrictions(int content_restrictions) { + CoreTabHelper* core_tab_helper = + CoreTabHelper::FromWebContents(web_contents()); + core_tab_helper->UpdateContentRestrictions(content_restrictions); +} diff --git a/chrome/browser/ui/pdf/pdf_tab_helper.h b/chrome/browser/ui/pdf/pdf_tab_helper.h index d50c86f..978c605 100644 --- a/chrome/browser/ui/pdf/pdf_tab_helper.h +++ b/chrome/browser/ui/pdf/pdf_tab_helper.h @@ -41,7 +41,10 @@ class PDFTabHelper : public content::WebContentsObserver, void UpdateLocationBar(); // Message handlers. - void OnPDFHasUnsupportedFeature(); + void OnHasUnsupportedFeature(); + void OnSaveURLAs(const GURL& url, + const content::Referrer& referrer); + void OnUpdateContentRestrictions(int content_restrictions); // The model for the confirmation prompt to open a PDF in Adobe Reader. scoped_ptr<OpenPDFInReaderPromptDelegate> open_in_reader_prompt_; diff --git a/chrome/browser/ui/tab_contents/core_tab_helper.cc b/chrome/browser/ui/tab_contents/core_tab_helper.cc index 748acb8..169e23a 100644 --- a/chrome/browser/ui/tab_contents/core_tab_helper.cc +++ b/chrome/browser/ui/tab_contents/core_tab_helper.cc @@ -7,6 +7,9 @@ #include "base/command_line.h" #include "base/metrics/histogram.h" #include "chrome/browser/renderer_host/web_cache_manager.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/browser_command_controller.h" +#include "chrome/browser/ui/browser_finder.h" #include "chrome/common/chrome_switches.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/render_view_host.h" @@ -21,7 +24,8 @@ DEFINE_WEB_CONTENTS_USER_DATA_KEY(CoreTabHelper); CoreTabHelper::CoreTabHelper(WebContents* web_contents) : content::WebContentsObserver(web_contents), - delegate_(NULL) { + delegate_(NULL), + content_restrictions_(0) { } CoreTabHelper::~CoreTabHelper() { @@ -110,9 +114,24 @@ void CoreTabHelper::OnUnloadDetachedStarted() { unload_detached_start_time_ = base::TimeTicks::Now(); } +void CoreTabHelper::UpdateContentRestrictions(int content_restrictions) { + content_restrictions_ = content_restrictions; +#if !defined(OS_ANDROID) + Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); + if (!browser) + return; + + browser->command_controller()->ContentRestrictionsChanged(); +#endif +} + //////////////////////////////////////////////////////////////////////////////// // WebContentsObserver overrides +void CoreTabHelper::DidStartLoading(content::RenderViewHost* render_view_host) { + UpdateContentRestrictions(0); +} + void CoreTabHelper::WasShown() { WebCacheManager::GetInstance()->ObserveActivity( web_contents()->GetRenderProcessHost()->GetID()); diff --git a/chrome/browser/ui/tab_contents/core_tab_helper.h b/chrome/browser/ui/tab_contents/core_tab_helper.h index c8e6782..7f0ffe3 100644 --- a/chrome/browser/ui/tab_contents/core_tab_helper.h +++ b/chrome/browser/ui/tab_contents/core_tab_helper.h @@ -39,6 +39,8 @@ class CoreTabHelper : public content::WebContentsObserver, // Set the time during close when the tab is no longer visible. void OnUnloadDetachedStarted(); + void UpdateContentRestrictions(int content_restrictions); + CoreTabHelperDelegate* delegate() const { return delegate_; } void set_delegate(CoreTabHelperDelegate* d) { delegate_ = d; } @@ -47,12 +49,15 @@ class CoreTabHelper : public content::WebContentsObserver, } base::TimeTicks new_tab_start_time() const { return new_tab_start_time_; } + int content_restrictions() const { return content_restrictions_; } private: explicit CoreTabHelper(content::WebContents* web_contents); friend class content::WebContentsUserData<CoreTabHelper>; // content::WebContentsObserver overrides: + virtual void DidStartLoading( + content::RenderViewHost* render_view_host) OVERRIDE; virtual void WasShown() OVERRIDE; virtual void WebContentsDestroyed( content::WebContents* web_contents) OVERRIDE; @@ -75,6 +80,10 @@ class CoreTabHelper : public content::WebContentsObserver, // The time when the tab was removed from view during close. base::TimeTicks unload_detached_start_time_; + // Content restrictions, used to disable print/copy etc based on content's + // (full-page plugins for now only) permissions. + int content_restrictions_; + DISALLOW_COPY_AND_ASSIGN(CoreTabHelper); }; |