Skip to content

Commit

Permalink
Remove chrome dependencies from app_window_api.cc
Browse files Browse the repository at this point in the history
Add OpenDevToolsWindow() and IsCurrentChannelOlderThanDev() to AppsClient.

BUG=387288

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

Cr-Commit-Position: refs/heads/master@{#291843}
  • Loading branch information
hashimoto authored and Commit bot committed Aug 26, 2014
1 parent 57c5309 commit 1bba58e
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 40 deletions.
9 changes: 9 additions & 0 deletions apps/ui/apps_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
#include <vector>

#include "apps/app_window.h"
#include "base/callback_forward.h"

namespace content {
class BrowserContext;
class WebContents;
}

namespace extensions {
Expand Down Expand Up @@ -43,6 +45,13 @@ class AppsClient {
virtual void IncrementKeepAliveCount() = 0;
virtual void DecrementKeepAliveCount() = 0;

// Opens DevTools window and runs the callback.
virtual void OpenDevToolsWindow(content::WebContents* web_contents,
const base::Closure& callback) = 0;

// Returns true if the current channel is older than dev.
virtual bool IsCurrentChannelOlderThanDev() = 0;

// Return the apps client.
static AppsClient* Get();

Expand Down
43 changes: 5 additions & 38 deletions chrome/browser/extensions/api/app_window/app_window_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
#include "base/strings/string_util.h"
#include "base/time/time.h"
#include "base/values.h"
#include "chrome/browser/devtools/devtools_window.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/api/app_window.h"
#include "chrome/common/extensions/features/feature_channel.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_types.h"
#include "content/public/browser/render_process_host.h"
Expand Down Expand Up @@ -69,34 +66,6 @@ const char kHtmlFrameOption[] = "experimental-html";

namespace {

// Opens an inspector window and delays the response to the
// AppWindowCreateFunction until the DevToolsWindow has finished loading, and is
// ready to stop on breakpoints in the callback.
class DevToolsRestorer : public base::RefCounted<DevToolsRestorer> {
public:
DevToolsRestorer(AppWindowCreateFunction* delayed_create_function,
content::WebContents* web_contents)
: delayed_create_function_(delayed_create_function) {
AddRef(); // Balanced in LoadCompleted.
DevToolsWindow* devtools_window = DevToolsWindow::OpenDevToolsWindow(
web_contents,
DevToolsToggleAction::ShowConsole());
devtools_window->SetLoadCompletedCallback(
base::Bind(&DevToolsRestorer::LoadCompleted, this));
}

private:
friend class base::RefCounted<DevToolsRestorer>;
~DevToolsRestorer() {}

void LoadCompleted() {
delayed_create_function_->SendDelayedResponse();
Release();
}

scoped_refptr<AppWindowCreateFunction> delayed_create_function_;
};

// If the same property is specified for the inner and outer bounds, raise an
// error.
bool CheckBoundsConflict(const scoped_ptr<int>& inner_property,
Expand Down Expand Up @@ -145,10 +114,6 @@ void CopyBoundsSpec(
AppWindowCreateFunction::AppWindowCreateFunction()
: inject_html_titlebar_(false) {}

void AppWindowCreateFunction::SendDelayedResponse() {
SendResponse(true);
}

bool AppWindowCreateFunction::RunAsync() {
// Don't create app window if the system is shutting down.
if (extensions::ExtensionsBrowserClient::Get()->IsShuttingDown())
Expand Down Expand Up @@ -230,7 +195,7 @@ bool AppWindowCreateFunction::RunAsync() {
if (!GetBoundsSpec(*options, &create_params, &error_))
return false;

if (GetCurrentChannel() <= chrome::VersionInfo::CHANNEL_DEV ||
if (!apps::AppsClient::Get()->IsCurrentChannelOlderThanDev() ||
extension()->location() == extensions::Manifest::COMPONENT) {
if (options->type == extensions::api::app_window::WINDOW_TYPE_PANEL) {
create_params.window_type = AppWindow::WINDOW_TYPE_PANEL;
Expand All @@ -249,7 +214,7 @@ bool AppWindowCreateFunction::RunAsync() {
"312745D9BF916161191143F6490085EEA0434997",
"53041A2FA309EECED01FFC751E7399186E860B2C"
};
if (GetCurrentChannel() > chrome::VersionInfo::CHANNEL_DEV &&
if (apps::AppsClient::Get()->IsCurrentChannelOlderThanDev() &&
!extensions::SimpleFeature::IsIdInList(
extension_id(),
std::set<std::string>(whitelist,
Expand Down Expand Up @@ -339,7 +304,9 @@ bool AppWindowCreateFunction::RunAsync() {

if (apps::AppWindowRegistry::Get(browser_context())
->HadDevToolsAttached(created_view)) {
new DevToolsRestorer(this, app_window->web_contents());
apps::AppsClient::Get()->OpenDevToolsWindow(
app_window->web_contents(),
base::Bind(&AppWindowCreateFunction::SendResponse, this, true));
return true;
}

Expand Down
2 changes: 0 additions & 2 deletions chrome/browser/extensions/api/app_window/app_window_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ class AppWindowCreateFunction : public AsyncExtensionFunction {
AppWindowCreateFunction();
DECLARE_EXTENSION_FUNCTION("app.window.create", APP_WINDOW_CREATE)

void SendDelayedResponse();

protected:
virtual ~AppWindowCreateFunction() {}
virtual bool RunAsync() OVERRIDE;
Expand Down
13 changes: 13 additions & 0 deletions chrome/browser/ui/apps/chrome_apps_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
#include "apps/app_window.h"
#include "base/memory/singleton.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/devtools/devtools_window.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/common/extensions/features/feature_channel.h"
#include "extensions/common/extension.h"

// TODO(jamescook): We probably shouldn't compile this class at all on Android.
Expand Down Expand Up @@ -68,3 +70,14 @@ void ChromeAppsClient::DecrementKeepAliveCount() {
chrome::DecrementKeepAliveCount();
#endif
}

void ChromeAppsClient::OpenDevToolsWindow(content::WebContents* web_contents,
const base::Closure& callback) {
DevToolsWindow* devtools_window = DevToolsWindow::OpenDevToolsWindow(
web_contents, DevToolsToggleAction::ShowConsole());
devtools_window->SetLoadCompletedCallback(callback);
}

bool ChromeAppsClient::IsCurrentChannelOlderThanDev() {
return extensions::GetCurrentChannel() > chrome::VersionInfo::CHANNEL_DEV;
}
3 changes: 3 additions & 0 deletions chrome/browser/ui/apps/chrome_apps_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class ChromeAppsClient : public apps::AppsClient {
const apps::AppWindow::CreateParams& params) OVERRIDE;
virtual void IncrementKeepAliveCount() OVERRIDE;
virtual void DecrementKeepAliveCount() OVERRIDE;
virtual void OpenDevToolsWindow(content::WebContents* web_contents,
const base::Closure& callback) OVERRIDE;
virtual bool IsCurrentChannelOlderThanDev() OVERRIDE;

// Implemented in platform specific code.
static extensions::NativeAppWindow* CreateNativeAppWindowImpl(
Expand Down

0 comments on commit 1bba58e

Please sign in to comment.