Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(835)

Side by Side Diff: chrome/browser/extensions/api/app_window/app_window_api.cc

Issue 11238055: Re-open DevTools windows for PackagedApps if they are reloaded with DevTools open. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: before unit test Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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::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
43 : public content::NotificationObserver {
44 public:
45 DelayedResponseForDevTools(AppWindowCreateFunction* parent,
46 content::RenderViewHost* created_view) :
47 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.
48
benwells 2012/10/23 06:18:48 nit: remove blank line.
tapted 2012/10/23 07:04:23 Done.
49 DevToolsWindow* devtools_window =
50 DevToolsWindow::ToggleDevToolsWindow(created_view,
51 true /* force_open */,
52 DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE);
53
54 registrar_.Add(this,
55 content::NOTIFICATION_LOAD_STOP,
56 content::Source<content::NavigationController>(
57 &devtools_window->tab_contents()
58 ->web_contents()->GetController()));
59 }
60 protected:
61 // content::NotificationObserver:
62 virtual void Observe(int type,
63 const content::NotificationSource& source,
64 const content::NotificationDetails& details) OVERRIDE {
65 DCHECK(type == content::NOTIFICATION_LOAD_STOP);
66 parent_->SendResponse(true);
67 parent_ = NULL;
68 }
69 private:
70 scoped_refptr<AppWindowCreateFunction> parent_;
71 content::NotificationRegistrar registrar_;
72 };
73
74 AppWindowCreateFunction::AppWindowCreateFunction() {
75 }
76
77 AppWindowCreateFunction::~AppWindowCreateFunction() {
78 }
79
34 bool AppWindowCreateFunction::RunImpl() { 80 bool AppWindowCreateFunction::RunImpl() {
35 scoped_ptr<Create::Params> params(Create::Params::Create(*args_)); 81 scoped_ptr<Create::Params> params(Create::Params::Create(*args_));
36 EXTENSION_FUNCTION_VALIDATE(params.get()); 82 EXTENSION_FUNCTION_VALIDATE(params.get());
37 83
38 GURL url = GetExtension()->GetResourceURL(params->url); 84 GURL url = GetExtension()->GetResourceURL(params->url);
39 // Allow absolute URLs for component apps, otherwise prepend the extension 85 // Allow absolute URLs for component apps, otherwise prepend the extension
40 // path. 86 // path.
41 if (GetExtension()->location() == extensions::Extension::COMPONENT) { 87 if (GetExtension()->location() == extensions::Extension::COMPONENT) {
42 GURL absolute = GURL(params->url); 88 GURL absolute = GURL(params->url);
43 if (absolute.has_scheme()) 89 if (absolute.has_scheme())
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 int view_id = MSG_ROUTING_NONE; 190 int view_id = MSG_ROUTING_NONE;
145 if (create_params.creator_process_id == created_view->GetProcess()->GetID()) 191 if (create_params.creator_process_id == created_view->GetProcess()->GetID())
146 view_id = created_view->GetRoutingID(); 192 view_id = created_view->GetRoutingID();
147 193
148 base::DictionaryValue* result = new base::DictionaryValue; 194 base::DictionaryValue* result = new base::DictionaryValue;
149 result->Set("viewId", base::Value::CreateIntegerValue(view_id)); 195 result->Set("viewId", base::Value::CreateIntegerValue(view_id));
150 result->Set("injectTitlebar", 196 result->Set("injectTitlebar",
151 base::Value::CreateBooleanValue(inject_html_titlebar)); 197 base::Value::CreateBooleanValue(inject_html_titlebar));
152 result->Set("id", base::Value::CreateStringValue(shell_window->window_key())); 198 result->Set("id", base::Value::CreateStringValue(shell_window->window_key()));
153 SetResult(result); 199 SetResult(result);
200
201 if (ShellWindowRegistry::Get(profile())->HadDevToolsAttached(created_view)) {
202 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.
203 } else {
204 SendResponse(true);
205 }
206
154 return true; 207 return true;
155 } 208 }
156 209
157 } // namespace extensions 210 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698