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/ui/extensions/shell_window.h" | 5 #include "chrome/browser/ui/extensions/shell_window.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/extensions/app_window_contents.h" | 9 #include "chrome/browser/extensions/app_window_contents.h" |
10 #include "chrome/browser/extensions/extension_process_manager.h" | 10 #include "chrome/browser/extensions/extension_process_manager.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 #endif | 65 #endif |
66 | 66 |
67 } // namespace | 67 } // namespace |
68 | 68 |
69 ShellWindow::CreateParams::CreateParams() | 69 ShellWindow::CreateParams::CreateParams() |
70 : window_type(ShellWindow::WINDOW_TYPE_DEFAULT), | 70 : window_type(ShellWindow::WINDOW_TYPE_DEFAULT), |
71 frame(ShellWindow::FRAME_CHROME), | 71 frame(ShellWindow::FRAME_CHROME), |
72 transparent_background(false), | 72 transparent_background(false), |
73 bounds(INT_MIN, INT_MIN, 0, 0), | 73 bounds(INT_MIN, INT_MIN, 0, 0), |
74 creator_process_id(0), | 74 creator_process_id(0), |
75 state(STATE_NORMAL), | 75 state(ui::SHOW_STATE_DEFAULT), |
76 hidden(false), | 76 hidden(false), |
77 resizable(true), | 77 resizable(true), |
78 focused(true) { | 78 focused(true) { |
79 } | 79 } |
80 | 80 |
81 ShellWindow::CreateParams::~CreateParams() { | 81 ShellWindow::CreateParams::~CreateParams() { |
82 } | 82 } |
83 | 83 |
84 ShellWindow* ShellWindow::Create(Profile* profile, | 84 ShellWindow* ShellWindow::Create(Profile* profile, |
85 const extensions::Extension* extension, | 85 const extensions::Extension* extension, |
(...skipping 11 matching lines...) Expand all Loading... |
97 : profile_(profile), | 97 : profile_(profile), |
98 extension_(extension), | 98 extension_(extension), |
99 window_type_(WINDOW_TYPE_DEFAULT), | 99 window_type_(WINDOW_TYPE_DEFAULT), |
100 image_loader_ptr_factory_(this), | 100 image_loader_ptr_factory_(this), |
101 fullscreen_for_window_api_(false), | 101 fullscreen_for_window_api_(false), |
102 fullscreen_for_tab_(false) { | 102 fullscreen_for_tab_(false) { |
103 } | 103 } |
104 | 104 |
105 void ShellWindow::Init(const GURL& url, | 105 void ShellWindow::Init(const GURL& url, |
106 ShellWindowContents* shell_window_contents, | 106 ShellWindowContents* shell_window_contents, |
107 const ShellWindow::CreateParams& params) { | 107 const CreateParams& params) { |
108 // Initialize the render interface and web contents | 108 // Initialize the render interface and web contents |
109 shell_window_contents_.reset(shell_window_contents); | 109 shell_window_contents_.reset(shell_window_contents); |
110 shell_window_contents_->Initialize(profile(), url); | 110 shell_window_contents_->Initialize(profile(), url); |
111 WebContents* web_contents = shell_window_contents_->GetWebContents(); | 111 WebContents* web_contents = shell_window_contents_->GetWebContents(); |
112 WebContentsModalDialogManager::CreateForWebContents(web_contents); | 112 WebContentsModalDialogManager::CreateForWebContents(web_contents); |
113 FaviconTabHelper::CreateForWebContents(web_contents); | 113 FaviconTabHelper::CreateForWebContents(web_contents); |
114 | 114 |
115 web_contents->SetDelegate(this); | 115 web_contents->SetDelegate(this); |
116 WebContentsModalDialogManager::FromWebContents(web_contents)-> | 116 WebContentsModalDialogManager::FromWebContents(web_contents)-> |
117 set_delegate(this); | 117 set_delegate(this); |
118 extensions::SetViewType(web_contents, extensions::VIEW_TYPE_APP_SHELL); | 118 extensions::SetViewType(web_contents, extensions::VIEW_TYPE_APP_SHELL); |
119 | 119 |
120 // Initialize the window | 120 // Initialize the window |
121 window_type_ = params.window_type; | 121 window_type_ = params.window_type; |
122 | 122 |
123 gfx::Rect bounds = params.bounds; | 123 gfx::Rect bounds = params.bounds; |
124 | 124 |
125 if (bounds.width() == 0) | 125 if (bounds.width() == 0) |
126 bounds.set_width(kDefaultWidth); | 126 bounds.set_width(kDefaultWidth); |
127 if (bounds.height() == 0) | 127 if (bounds.height() == 0) |
128 bounds.set_height(kDefaultHeight); | 128 bounds.set_height(kDefaultHeight); |
129 | 129 |
130 // If left and top are left undefined, the native shell window will center | 130 // If left and top are left undefined, the native shell window will center |
131 // the window on the main screen in a platform-defined manner. | 131 // the window on the main screen in a platform-defined manner. |
132 | 132 |
| 133 ui::WindowShowState cached_state = ui::SHOW_STATE_DEFAULT; |
133 if (!params.window_key.empty()) { | 134 if (!params.window_key.empty()) { |
134 window_key_ = params.window_key; | 135 window_key_ = params.window_key; |
135 | 136 |
136 extensions::ShellWindowGeometryCache* cache = | 137 extensions::ShellWindowGeometryCache* cache = |
137 extensions::ExtensionSystem::Get(profile())-> | 138 extensions::ExtensionSystem::Get(profile())-> |
138 shell_window_geometry_cache(); | 139 shell_window_geometry_cache(); |
139 gfx::Rect cached_bounds; | 140 gfx::Rect cached_bounds; |
140 if (cache->GetGeometry(extension()->id(), params.window_key, | 141 if (cache->GetGeometry(extension()->id(), params.window_key, |
141 &cached_bounds)) | 142 &cached_bounds, &cached_state)) { |
142 bounds = cached_bounds; | 143 bounds = cached_bounds; |
| 144 } |
143 } | 145 } |
144 | 146 |
145 ShellWindow::CreateParams new_params = params; | 147 CreateParams new_params = params; |
146 | 148 |
147 gfx::Size& minimum_size = new_params.minimum_size; | 149 gfx::Size& minimum_size = new_params.minimum_size; |
148 gfx::Size& maximum_size = new_params.maximum_size; | 150 gfx::Size& maximum_size = new_params.maximum_size; |
149 | 151 |
150 // In the case that minimum size > maximum size, we consider the minimum | 152 // In the case that minimum size > maximum size, we consider the minimum |
151 // size to be more important. | 153 // size to be more important. |
152 if (maximum_size.width() && maximum_size.width() < minimum_size.width()) | 154 if (maximum_size.width() && maximum_size.width() < minimum_size.width()) |
153 maximum_size.set_width(minimum_size.width()); | 155 maximum_size.set_width(minimum_size.width()); |
154 if (maximum_size.height() && maximum_size.height() < minimum_size.height()) | 156 if (maximum_size.height() && maximum_size.height() < minimum_size.height()) |
155 maximum_size.set_height(minimum_size.height()); | 157 maximum_size.set_height(minimum_size.height()); |
156 | 158 |
157 if (maximum_size.width() && bounds.width() > maximum_size.width()) | 159 if (maximum_size.width() && bounds.width() > maximum_size.width()) |
158 bounds.set_width(maximum_size.width()); | 160 bounds.set_width(maximum_size.width()); |
159 if (bounds.width() != INT_MIN && bounds.width() < minimum_size.width()) | 161 if (bounds.width() != INT_MIN && bounds.width() < minimum_size.width()) |
160 bounds.set_width(minimum_size.width()); | 162 bounds.set_width(minimum_size.width()); |
161 | 163 |
162 if (maximum_size.height() && bounds.height() > maximum_size.height()) | 164 if (maximum_size.height() && bounds.height() > maximum_size.height()) |
163 bounds.set_height(maximum_size.height()); | 165 bounds.set_height(maximum_size.height()); |
164 if (bounds.height() != INT_MIN && bounds.height() < minimum_size.height()) | 166 if (bounds.height() != INT_MIN && bounds.height() < minimum_size.height()) |
165 bounds.set_height(minimum_size.height()); | 167 bounds.set_height(minimum_size.height()); |
166 | 168 |
167 new_params.bounds = bounds; | 169 new_params.bounds = bounds; |
168 | 170 |
| 171 if (cached_state != ui::SHOW_STATE_DEFAULT) |
| 172 new_params.state = cached_state; |
| 173 |
169 native_app_window_.reset(NativeAppWindow::Create(this, new_params)); | 174 native_app_window_.reset(NativeAppWindow::Create(this, new_params)); |
170 OnNativeWindowChanged(); | |
171 | 175 |
172 switch (params.state) { | 176 if (!new_params.hidden) { |
173 case CreateParams::STATE_NORMAL: | |
174 break; | |
175 case CreateParams::STATE_FULLSCREEN: | |
176 Fullscreen(); | |
177 break; | |
178 case CreateParams::STATE_MAXIMIZED: | |
179 Maximize(); | |
180 break; | |
181 case CreateParams::STATE_MINIMIZED: | |
182 Minimize(); | |
183 break; | |
184 } | |
185 | |
186 if (!params.hidden) { | |
187 if (window_type_is_panel()) | 177 if (window_type_is_panel()) |
188 GetBaseWindow()->ShowInactive(); // Panels are not activated by default. | 178 GetBaseWindow()->ShowInactive(); // Panels are not activated by default. |
189 else | 179 else |
190 GetBaseWindow()->Show(); | 180 GetBaseWindow()->Show(); |
191 } | 181 } |
192 | 182 |
| 183 if (new_params.state == ui::SHOW_STATE_FULLSCREEN) |
| 184 Fullscreen(); |
| 185 else if (new_params.state == ui::SHOW_STATE_MAXIMIZED) |
| 186 Maximize(); |
| 187 else if (new_params.state == ui::SHOW_STATE_MINIMIZED) |
| 188 Minimize(); |
| 189 |
| 190 OnNativeWindowChanged(); |
| 191 |
193 // When the render view host is changed, the native window needs to know | 192 // When the render view host is changed, the native window needs to know |
194 // about it in case it has any setup to do to make the renderer appear | 193 // about it in case it has any setup to do to make the renderer appear |
195 // properly. In particular, on Windows, the view's clickthrough region needs | 194 // properly. In particular, on Windows, the view's clickthrough region needs |
196 // to be set. | 195 // to be set. |
197 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, | 196 registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CHANGED, |
198 content::Source<content::NavigationController>( | 197 content::Source<content::NavigationController>( |
199 &web_contents->GetController())); | 198 &web_contents->GetController())); |
200 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 199 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
201 content::Source<Profile>(profile_)); | 200 content::Source<Profile>(profile_)); |
202 // Close when the browser is exiting. | 201 // Close when the browser is exiting. |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
569 return; | 568 return; |
570 if (!native_app_window_) | 569 if (!native_app_window_) |
571 return; | 570 return; |
572 | 571 |
573 extensions::ShellWindowGeometryCache* cache = | 572 extensions::ShellWindowGeometryCache* cache = |
574 extensions::ExtensionSystem::Get(profile())-> | 573 extensions::ExtensionSystem::Get(profile())-> |
575 shell_window_geometry_cache(); | 574 shell_window_geometry_cache(); |
576 | 575 |
577 gfx::Rect bounds = native_app_window_->GetRestoredBounds(); | 576 gfx::Rect bounds = native_app_window_->GetRestoredBounds(); |
578 bounds.Inset(native_app_window_->GetFrameInsets()); | 577 bounds.Inset(native_app_window_->GetFrameInsets()); |
579 cache->SaveGeometry(extension()->id(), window_key_, bounds); | 578 ui::WindowShowState window_state = native_app_window_->GetRestoredState(); |
| 579 cache->SaveGeometry(extension()->id(), window_key_, bounds, window_state); |
580 } | 580 } |
581 | 581 |
582 // static | 582 // static |
583 SkRegion* ShellWindow::RawDraggableRegionsToSkRegion( | 583 SkRegion* ShellWindow::RawDraggableRegionsToSkRegion( |
584 const std::vector<extensions::DraggableRegion>& regions) { | 584 const std::vector<extensions::DraggableRegion>& regions) { |
585 SkRegion* sk_region = new SkRegion; | 585 SkRegion* sk_region = new SkRegion; |
586 for (std::vector<extensions::DraggableRegion>::const_iterator iter = | 586 for (std::vector<extensions::DraggableRegion>::const_iterator iter = |
587 regions.begin(); | 587 regions.begin(); |
588 iter != regions.end(); ++iter) { | 588 iter != regions.end(); ++iter) { |
589 const extensions::DraggableRegion& region = *iter; | 589 const extensions::DraggableRegion& region = *iter; |
590 sk_region->op( | 590 sk_region->op( |
591 region.bounds.x(), | 591 region.bounds.x(), |
592 region.bounds.y(), | 592 region.bounds.y(), |
593 region.bounds.right(), | 593 region.bounds.right(), |
594 region.bounds.bottom(), | 594 region.bounds.bottom(), |
595 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); | 595 region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op); |
596 } | 596 } |
597 return sk_region; | 597 return sk_region; |
598 } | 598 } |
OLD | NEW |