| 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/time.h" | 7 #include "base/time.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/extensions/shell_window_registry.h" | |
| 10 #include "chrome/browser/extensions/window_controller.h" | 9 #include "chrome/browser/extensions/window_controller.h" |
| 11 #include "chrome/browser/ui/extensions/shell_window.h" | 10 #include "chrome/browser/ui/extensions/shell_window.h" |
| 12 #include "chrome/common/extensions/api/app_window.h" | 11 #include "chrome/common/extensions/api/app_window.h" |
| 13 #include "chrome/common/extensions/extension_error_utils.h" | |
| 14 #include "content/public/browser/render_view_host.h" | 12 #include "content/public/browser/render_view_host.h" |
| 15 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 16 #include "content/public/common/url_constants.h" | 14 #include "content/public/common/url_constants.h" |
| 17 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 18 #include "ui/gfx/rect.h" | 16 #include "ui/gfx/rect.h" |
| 19 | 17 |
| 20 namespace app_window = extensions::api::app_window; | 18 namespace app_window = extensions::api::app_window; |
| 21 namespace Create = app_window::Create; | 19 namespace Create = app_window::Create; |
| 22 | 20 |
| 23 namespace extensions { | 21 namespace extensions { |
| 24 | 22 |
| 25 namespace app_window_constants { | 23 namespace app_window_constants { |
| 26 const char kNoAssociatedShellWindow[] = | |
| 27 "The context from which the function was called did not have an " | |
| 28 "associated shell window."; | |
| 29 const char kInvalidWindowId[] = | 24 const char kInvalidWindowId[] = |
| 30 "The window id can not be more than 256 characters long."; | 25 "The window id can not be more than 256 characters long."; |
| 31 }; | 26 }; |
| 32 | 27 |
| 33 bool AppWindowExtensionFunction::RunImpl() { | |
| 34 ShellWindowRegistry* registry = ShellWindowRegistry::Get(profile()); | |
| 35 CHECK(registry); | |
| 36 content::RenderViewHost* rvh = render_view_host(); | |
| 37 if (!rvh) | |
| 38 // No need to set an error, since we won't return to the caller anyway if | |
| 39 // there's no RVH. | |
| 40 return false; | |
| 41 ShellWindow* window = registry->GetShellWindowForRenderViewHost(rvh); | |
| 42 if (!window) { | |
| 43 error_ = app_window_constants::kNoAssociatedShellWindow; | |
| 44 return false; | |
| 45 } | |
| 46 return RunWithWindow(window); | |
| 47 } | |
| 48 | |
| 49 const char kNoneFrameOption[] = "none"; | 28 const char kNoneFrameOption[] = "none"; |
| 50 | 29 |
| 51 bool AppWindowCreateFunction::RunImpl() { | 30 bool AppWindowCreateFunction::RunImpl() { |
| 52 scoped_ptr<Create::Params> params(Create::Params::Create(*args_)); | 31 scoped_ptr<Create::Params> params(Create::Params::Create(*args_)); |
| 53 EXTENSION_FUNCTION_VALIDATE(params.get()); | 32 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 54 | 33 |
| 55 GURL url = GetExtension()->GetResourceURL(params->url); | 34 GURL url = GetExtension()->GetResourceURL(params->url); |
| 56 | 35 |
| 57 // TODO(jeremya): figure out a way to pass the opening WebContents through to | 36 // TODO(jeremya): figure out a way to pass the opening WebContents through to |
| 58 // ShellWindow::Create so we can set the opener at create time rather than | 37 // ShellWindow::Create so we can set the opener at create time rather than |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 ShellWindow::Create(profile(), GetExtension(), url, create_params); | 115 ShellWindow::Create(profile(), GetExtension(), url, create_params); |
| 137 shell_window->GetBaseWindow()->Show(); | 116 shell_window->GetBaseWindow()->Show(); |
| 138 | 117 |
| 139 content::WebContents* created_contents = shell_window->web_contents(); | 118 content::WebContents* created_contents = shell_window->web_contents(); |
| 140 int view_id = created_contents->GetRenderViewHost()->GetRoutingID(); | 119 int view_id = created_contents->GetRenderViewHost()->GetRoutingID(); |
| 141 | 120 |
| 142 SetResult(base::Value::CreateIntegerValue(view_id)); | 121 SetResult(base::Value::CreateIntegerValue(view_id)); |
| 143 return true; | 122 return true; |
| 144 } | 123 } |
| 145 | 124 |
| 146 bool AppWindowFocusFunction::RunWithWindow(ShellWindow* window) { | |
| 147 window->GetBaseWindow()->Activate(); | |
| 148 return true; | |
| 149 } | |
| 150 | |
| 151 bool AppWindowMaximizeFunction::RunWithWindow(ShellWindow* window) { | |
| 152 window->GetBaseWindow()->Maximize(); | |
| 153 return true; | |
| 154 } | |
| 155 | |
| 156 bool AppWindowMinimizeFunction::RunWithWindow(ShellWindow* window) { | |
| 157 window->GetBaseWindow()->Minimize(); | |
| 158 return true; | |
| 159 } | |
| 160 | |
| 161 bool AppWindowRestoreFunction::RunWithWindow(ShellWindow* window) { | |
| 162 window->GetBaseWindow()->Restore(); | |
| 163 return true; | |
| 164 } | |
| 165 | |
| 166 } // namespace extensions | 125 } // namespace extensions |
| OLD | NEW |