| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/api/app_window/app_window_api.h" | 5 #include "chrome/browser/extensions/api/app_window/app_window_api.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/time.h" | 8 #include "base/time.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/debugger/devtools_window.h" |
| 11 #include "chrome/browser/extensions/shell_window_registry.h" |
| 10 #include "chrome/browser/extensions/window_controller.h" | 12 #include "chrome/browser/extensions/window_controller.h" |
| 11 #include "chrome/browser/ui/extensions/shell_window.h" | 13 #include "chrome/browser/ui/extensions/shell_window.h" |
| 14 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 12 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 13 #include "chrome/common/extensions/api/app_window.h" | 16 #include "chrome/common/extensions/api/app_window.h" |
| 17 #include "content/public/browser/notification_registrar.h" |
| 18 #include "content/public/browser/notification_types.h" |
| 14 #include "content/public/browser/render_process_host.h" | 19 #include "content/public/browser/render_process_host.h" |
| 15 #include "content/public/browser/render_view_host.h" | 20 #include "content/public/browser/render_view_host.h" |
| 16 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 17 #include "content/public/common/url_constants.h" | 22 #include "content/public/common/url_constants.h" |
| 18 #include "googleurl/src/gurl.h" | 23 #include "googleurl/src/gurl.h" |
| 19 #include "ui/gfx/rect.h" | 24 #include "ui/gfx/rect.h" |
| 20 | 25 |
| 21 namespace app_window = extensions::api::app_window; | 26 namespace app_window = extensions::api::app_window; |
| 22 namespace Create = app_window::Create; | 27 namespace Create = app_window::Create; |
| 23 | 28 |
| 24 namespace extensions { | 29 namespace extensions { |
| 25 | 30 |
| 26 namespace app_window_constants { | 31 namespace app_window_constants { |
| 27 const char kInvalidWindowId[] = | 32 const char kInvalidWindowId[] = |
| 28 "The window id can not be more than 256 characters long."; | 33 "The window id can not be more than 256 characters long."; |
| 29 }; | 34 } |
| 30 | 35 |
| 31 const char kNoneFrameOption[] = "none"; | 36 const char kNoneFrameOption[] = "none"; |
| 32 const char kHtmlFrameOption[] = "experimental-html"; | 37 const char kHtmlFrameOption[] = "experimental-html"; |
| 33 | 38 |
| 39 // Opens an inspector window and delays the response to the |
| 40 // AppWindowCreateFunction until the DevToolsWindow has finished loading, and is |
| 41 // ready to stop on breakpoints in the callback. |
| 42 class AppWindowCreateFunction::DevToolsRestorer |
| 43 : public content::NotificationObserver { |
| 44 public: |
| 45 DevToolsRestorer(AppWindowCreateFunction* parent, |
| 46 content::RenderViewHost* created_view) |
| 47 : parent_(parent) { |
| 48 DevToolsWindow* devtools_window = |
| 49 DevToolsWindow::ToggleDevToolsWindow(created_view, |
| 50 true /* force_open */, |
| 51 DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE); |
| 52 |
| 53 registrar_.Add(this, |
| 54 content::NOTIFICATION_LOAD_STOP, |
| 55 content::Source<content::NavigationController>( |
| 56 &devtools_window->tab_contents() |
| 57 ->web_contents()->GetController())); |
| 58 } |
| 59 protected: |
| 60 // content::NotificationObserver: |
| 61 virtual void Observe(int type, |
| 62 const content::NotificationSource& source, |
| 63 const content::NotificationDetails& details) OVERRIDE { |
| 64 DCHECK(type == content::NOTIFICATION_LOAD_STOP); |
| 65 parent_->SendResponse(true); |
| 66 parent_ = NULL; |
| 67 } |
| 68 private: |
| 69 scoped_refptr<AppWindowCreateFunction> parent_; |
| 70 content::NotificationRegistrar registrar_; |
| 71 }; |
| 72 |
| 73 AppWindowCreateFunction::AppWindowCreateFunction() { |
| 74 } |
| 75 |
| 76 AppWindowCreateFunction::~AppWindowCreateFunction() { |
| 77 } |
| 78 |
| 34 bool AppWindowCreateFunction::RunImpl() { | 79 bool AppWindowCreateFunction::RunImpl() { |
| 35 scoped_ptr<Create::Params> params(Create::Params::Create(*args_)); | 80 scoped_ptr<Create::Params> params(Create::Params::Create(*args_)); |
| 36 EXTENSION_FUNCTION_VALIDATE(params.get()); | 81 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 37 | 82 |
| 38 GURL url = GetExtension()->GetResourceURL(params->url); | 83 GURL url = GetExtension()->GetResourceURL(params->url); |
| 39 // Allow absolute URLs for component apps, otherwise prepend the extension | 84 // Allow absolute URLs for component apps, otherwise prepend the extension |
| 40 // path. | 85 // path. |
| 41 if (GetExtension()->location() == extensions::Extension::COMPONENT) { | 86 if (GetExtension()->location() == extensions::Extension::COMPONENT) { |
| 42 GURL absolute = GURL(params->url); | 87 GURL absolute = GURL(params->url); |
| 43 if (absolute.has_scheme()) | 88 if (absolute.has_scheme()) |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 int view_id = MSG_ROUTING_NONE; | 189 int view_id = MSG_ROUTING_NONE; |
| 145 if (create_params.creator_process_id == created_view->GetProcess()->GetID()) | 190 if (create_params.creator_process_id == created_view->GetProcess()->GetID()) |
| 146 view_id = created_view->GetRoutingID(); | 191 view_id = created_view->GetRoutingID(); |
| 147 | 192 |
| 148 base::DictionaryValue* result = new base::DictionaryValue; | 193 base::DictionaryValue* result = new base::DictionaryValue; |
| 149 result->Set("viewId", base::Value::CreateIntegerValue(view_id)); | 194 result->Set("viewId", base::Value::CreateIntegerValue(view_id)); |
| 150 result->Set("injectTitlebar", | 195 result->Set("injectTitlebar", |
| 151 base::Value::CreateBooleanValue(inject_html_titlebar)); | 196 base::Value::CreateBooleanValue(inject_html_titlebar)); |
| 152 result->Set("id", base::Value::CreateStringValue(shell_window->window_key())); | 197 result->Set("id", base::Value::CreateStringValue(shell_window->window_key())); |
| 153 SetResult(result); | 198 SetResult(result); |
| 199 |
| 200 if (ShellWindowRegistry::Get(profile())->HadDevToolsAttached(created_view)) { |
| 201 delay_response_.reset(new DevToolsRestorer(this, created_view)); |
| 202 return true; |
| 203 } |
| 204 |
| 205 SendResponse(true); |
| 154 return true; | 206 return true; |
| 155 } | 207 } |
| 156 | 208 |
| 157 } // namespace extensions | 209 } // namespace extensions |
| OLD | NEW |