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..e5a90c2d602e54f3232f5acfb80ac592cc0520d0 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"; |
| +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 content::NotificationObserver { |
| + public: |
| + DevToolsRestorer(AppWindowCreateFunction* delayed_create_function, |
| + content::RenderViewHost* created_view) |
| + : delayed_create_function_(delayed_create_function) { |
| + DevToolsWindow* devtools_window = |
| + DevToolsWindow::ToggleDevToolsWindow(created_view, |
|
benwells
2012/10/24 03:24:08
Nit: created_view on next line
tapted
2012/10/24 04:03:57
Done.
|
| + true /* force_open */, |
| + DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE); |
| + |
| + registrar_.Add(this, |
|
benwells
2012/10/24 03:24:08
Maybe if this goes on the next line you won't need
tapted
2012/10/24 04:03:57
Done.
|
| + content::NOTIFICATION_LOAD_STOP, |
| + content::Source<content::NavigationController>( |
| + &devtools_window->tab_contents() |
| + ->web_contents()->GetController())); |
| + } |
|
benwells
2012/10/24 03:24:08
Blank line before protected:
tapted
2012/10/24 04:03:57
Done.
|
| + protected: |
| + // content::NotificationObserver: |
| + virtual void Observe(int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) OVERRIDE { |
| + DCHECK(type == content::NOTIFICATION_LOAD_STOP); |
| + delayed_create_function_->SendDelayedResponse(); |
| + delete this; |
| + } |
| + private: |
|
benwells
2012/10/24 03:24:08
Blank line before private:
tapted
2012/10/24 04:03:57
Done.
|
| + scoped_refptr<AppWindowCreateFunction> delayed_create_function_; |
| + content::NotificationRegistrar registrar_; |
| +}; |
| + |
| +} // namespace |
| + |
| +void AppWindowCreateFunction::SendDelayedResponse() { |
| + SendResponse(true); |
| +} |
| + |
| 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)) { |
| + new DevToolsRestorer(this, created_view); |
| + return true; |
| + } |
| + |
| + SendResponse(true); |
| return true; |
| } |