Skip to content

Commit

Permalink
Remove ExtensionHost dependencies on file/color picker and browser_sh…
Browse files Browse the repository at this point in the history
…utdown

* Move file and color picker support to ExtensionViewHost, because they can
  only be spawned by a click on a visible page element in a UI view.
* Set RenderProcessHostImpl fast_shutdown_started_ slightly earlier and use
  it to check for fast shutdown in ExtensionHost

This is part of the app_shell extensions refactor project.

BUG=321341
TEST=browser_tests

Review URL: https://codereview.chromium.org/111553004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@239990 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
jamescook@chromium.org committed Dec 11, 2013
1 parent e51726c commit 2dcd62b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 28 deletions.
22 changes: 3 additions & 19 deletions chrome/browser/extensions/extension_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,14 @@
#include "base/metrics/histogram.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/browser_shutdown.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/error_console/error_console.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/extensions/extension_tab_util.h"
#include "chrome/browser/extensions/extension_web_contents_observer.h"
#include "chrome/browser/file_select_helper.h"
#include "chrome/browser/media/media_capture_devices_dispatcher.h"
#include "chrome/browser/ui/app_modal_dialogs/javascript_dialog_manager.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/prefs/prefs_tab_helper.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/extensions/extension_constants.h"
Expand All @@ -51,11 +48,9 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/window_open_disposition.h"

using blink::WebDragOperation;
using blink::WebDragOperationsMask;
using content::BrowserContext;
using content::NativeWebKeyboardEvent;
using content::OpenURLParams;
using content::RenderProcessHost;
using content::RenderViewHost;
using content::SiteInstance;
using content::WebContents;
Expand Down Expand Up @@ -249,7 +244,8 @@ void ExtensionHost::RenderProcessGone(base::TerminationStatus status) {
// During browser shutdown, we may use sudden termination on an extension
// process, so it is expected to lose our connection to the render view.
// Do nothing.
if (browser_shutdown::GetShutdownType() != browser_shutdown::NOT_VALID)
RenderProcessHost* process_host = host_contents_->GetRenderProcessHost();
if (process_host && process_host->FastShutdownStarted())
return;

// In certain cases, multiple ExtensionHost objects may have pointed to
Expand Down Expand Up @@ -436,18 +432,6 @@ content::JavaScriptDialogManager* ExtensionHost::GetJavaScriptDialogManager() {
return dialog_manager_.get();
}

content::ColorChooser* ExtensionHost::OpenColorChooser(
WebContents* web_contents,
SkColor initial_color,
const std::vector<content::ColorSuggestion>& suggestions) {
return chrome::ShowColorChooser(web_contents, initial_color);
}

void ExtensionHost::RunFileChooser(WebContents* tab,
const content::FileChooserParams& params) {
FileSelectHelper::RunFileChooser(tab, params);
}

void ExtensionHost::AddNewContents(WebContents* source,
WebContents* new_contents,
WindowOpenDisposition disposition,
Expand Down
7 changes: 0 additions & 7 deletions chrome/browser/extensions/extension_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,6 @@ class ExtensionHost : public content::WebContentsDelegate,
// content::WebContentsDelegate
virtual content::JavaScriptDialogManager*
GetJavaScriptDialogManager() OVERRIDE;
virtual content::ColorChooser* OpenColorChooser(
content::WebContents* web_contents,
SkColor color,
const std::vector<content::ColorSuggestion>& suggestions) OVERRIDE;
virtual void RunFileChooser(
content::WebContents* tab,
const content::FileChooserParams& params) OVERRIDE;
virtual void AddNewContents(content::WebContents* source,
content::WebContents* new_contents,
WindowOpenDisposition disposition,
Expand Down
27 changes: 26 additions & 1 deletion chrome/browser/extensions/extension_view_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/extensions/window_controller.h"
#include "chrome/browser/file_select_helper.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/common/extensions/extension_messages.h"
#include "components/web_modal/web_contents_modal_dialog_manager.h"
#include "content/public/browser/notification_source.h"
Expand Down Expand Up @@ -161,6 +163,8 @@ bool ExtensionViewHost::IsBackgroundPage() const {
return false;
}

// content::WebContentsDelegate overrides:

WebContents* ExtensionViewHost::OpenURLFromTab(
WebContents* source,
const OpenURLParams& params) {
Expand Down Expand Up @@ -217,12 +221,31 @@ void ExtensionViewHost::HandleKeyboardEvent(
UnhandledKeyboardEvent(source, event);
}

content::ColorChooser* ExtensionViewHost::OpenColorChooser(
WebContents* web_contents,
SkColor initial_color,
const std::vector<content::ColorSuggestion>& suggestions) {
// Similar to the file chooser below, opening a color chooser requires a
// visible <input> element to click on. Therefore this code only exists for
// extensions with a view.
return chrome::ShowColorChooser(web_contents, initial_color);
}

void ExtensionViewHost::RunFileChooser(
WebContents* tab,
const content::FileChooserParams& params) {
// For security reasons opening a file picker requires a visible <input>
// element to click on, so this code only exists for extensions with a view.
FileSelectHelper::RunFileChooser(tab, params);
}


void ExtensionViewHost::ResizeDueToAutoResize(WebContents* source,
const gfx::Size& new_size) {
view_->ResizeDueToAutoResize(new_size);
}

// content::WebContentsObserver
// content::WebContentsObserver overrides:

void ExtensionViewHost::RenderViewCreated(RenderViewHost* render_view_host) {
ExtensionHost::RenderViewCreated(render_view_host);
Expand All @@ -238,6 +261,8 @@ void ExtensionViewHost::RenderViewCreated(RenderViewHost* render_view_host) {
}
}

// web_modal::WebContentsModalDialogManagerDelegate overrides:

web_modal::WebContentsModalDialogHost*
ExtensionViewHost::GetWebContentsModalDialogHost() {
return this;
Expand Down
7 changes: 7 additions & 0 deletions chrome/browser/extensions/extension_view_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ class ExtensionViewHost
virtual void HandleKeyboardEvent(
content::WebContents* source,
const content::NativeWebKeyboardEvent& event) OVERRIDE;
virtual content::ColorChooser* OpenColorChooser(
content::WebContents* web_contents,
SkColor color,
const std::vector<content::ColorSuggestion>& suggestions) OVERRIDE;
virtual void RunFileChooser(
content::WebContents* tab,
const content::FileChooserParams& params) OVERRIDE;
virtual void ResizeDueToAutoResize(content::WebContents* source,
const gfx::Size& new_size) OVERRIDE;

Expand Down
5 changes: 4 additions & 1 deletion content/browser/renderer_host/render_process_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1200,8 +1200,11 @@ bool RenderProcessHostImpl::FastShutdownIfPossible() {
if (!SuddenTerminationAllowed())
return false;

ProcessDied(false /* already_dead */);
// Set this before ProcessDied() so observers can tell if the render process
// died due to fast shutdown versus another cause.
fast_shutdown_started_ = true;

ProcessDied(false /* already_dead */);
return true;
}

Expand Down

0 comments on commit 2dcd62b

Please sign in to comment.