Chromium Code Reviews| Index: chrome/browser/extensions/api/app_window/app_window_api.cc |
| diff --git a/chrome/browser/extensions/api/app_window/app_window_api.cc b/chrome/browser/extensions/api/app_window/app_window_api.cc |
| index 34e855581da5ec160f0edbce45c32c6757d2c38b..5c3262faa3d0f2e486131a7ba6ab2107ee8ad4d9 100644 |
| --- a/chrome/browser/extensions/api/app_window/app_window_api.cc |
| +++ b/chrome/browser/extensions/api/app_window/app_window_api.cc |
| @@ -7,10 +7,15 @@ |
| #include "base/command_line.h" |
| #include "base/time.h" |
| #include "base/values.h" |
| +#include "chrome/browser/debugger/devtools_window.h" |
| +#include "chrome/browser/extensions/shell_window_registry.h" |
| #include "chrome/browser/extensions/window_controller.h" |
| #include "chrome/browser/ui/extensions/shell_window.h" |
| +#include "chrome/browser/ui/tab_contents/tab_contents.h" |
| #include "chrome/common/chrome_switches.h" |
| #include "chrome/common/extensions/api/app_window.h" |
| +#include "content/public/browser/notification_registrar.h" |
| +#include "content/public/browser/notification_types.h" |
| #include "content/public/browser/render_process_host.h" |
| #include "content/public/browser/render_view_host.h" |
| #include "content/public/browser/web_contents.h" |
| @@ -26,11 +31,52 @@ namespace extensions { |
| namespace app_window_constants { |
| const char kInvalidWindowId[] = |
| "The window id can not be more than 256 characters long."; |
| -}; |
| +} |
| const char kNoneFrameOption[] = "none"; |
| const char kHtmlFrameOption[] = "experimental-html"; |
| +// 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 AppWindowCreateFunction::DelayedResponseForDevTools |
|
benwells
2012/10/23 06:18:48
Hmmm, naming is always hard, but I think we can do
tapted
2012/10/23 07:04:23
Done. (I actually picked the name in an early vers
|
| + : public content::NotificationObserver { |
| + public: |
| + DelayedResponseForDevTools(AppWindowCreateFunction* parent, |
| + content::RenderViewHost* created_view) : |
| + parent_(parent) { |
|
benwells
2012/10/23 06:18:48
nit: colon goes on this line, like so:
: paren
tapted
2012/10/23 07:04:23
Done.
|
| + |
|
benwells
2012/10/23 06:18:48
nit: remove blank line.
tapted
2012/10/23 07:04:23
Done.
|
| + DevToolsWindow* devtools_window = |
| + DevToolsWindow::ToggleDevToolsWindow(created_view, |
| + true /* force_open */, |
| + DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE); |
| + |
| + registrar_.Add(this, |
| + content::NOTIFICATION_LOAD_STOP, |
| + content::Source<content::NavigationController>( |
| + &devtools_window->tab_contents() |
| + ->web_contents()->GetController())); |
| + } |
| + protected: |
| + // content::NotificationObserver: |
| + virtual void Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) OVERRIDE { |
| + DCHECK(type == content::NOTIFICATION_LOAD_STOP); |
| + parent_->SendResponse(true); |
| + parent_ = NULL; |
| + } |
| + private: |
| + scoped_refptr<AppWindowCreateFunction> parent_; |
| + content::NotificationRegistrar registrar_; |
| +}; |
| + |
| +AppWindowCreateFunction::AppWindowCreateFunction() { |
| +} |
| + |
| +AppWindowCreateFunction::~AppWindowCreateFunction() { |
| +} |
| + |
| bool AppWindowCreateFunction::RunImpl() { |
| scoped_ptr<Create::Params> params(Create::Params::Create(*args_)); |
| EXTENSION_FUNCTION_VALIDATE(params.get()); |
| @@ -151,6 +197,13 @@ bool AppWindowCreateFunction::RunImpl() { |
| base::Value::CreateBooleanValue(inject_html_titlebar)); |
| result->Set("id", base::Value::CreateStringValue(shell_window->window_key())); |
| SetResult(result); |
| + |
| + if (ShellWindowRegistry::Get(profile())->HadDevToolsAttached(created_view)) { |
| + delay_response_.reset(new DelayedResponseForDevTools(this, created_view)); |
|
benwells
2012/10/23 06:18:48
nit: early return true here instead of else.
tapted
2012/10/23 07:04:23
Done.
|
| + } else { |
| + SendResponse(true); |
| + } |
| + |
| return true; |
| } |