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/tab_helper.h" | 5 #include "chrome/browser/extensions/tab_helper.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 | 141 |
142 bool TabHelper::CanCreateApplicationShortcuts() const { | 142 bool TabHelper::CanCreateApplicationShortcuts() const { |
143 #if defined(OS_MACOSX) | 143 #if defined(OS_MACOSX) |
144 return false; | 144 return false; |
145 #else | 145 #else |
146 return web_app::IsValidUrl(web_contents()->GetURL()); | 146 return web_app::IsValidUrl(web_contents()->GetURL()); |
147 #endif | 147 #endif |
148 } | 148 } |
149 | 149 |
150 bool TabHelper::CanCreateBookmarkApp() const { | 150 bool TabHelper::CanCreateBookmarkApp() const { |
151 #if defined(OS_MACOSX) | |
152 return false; | |
153 #else | |
154 return IsValidBookmarkAppUrl(web_contents()->GetURL()); | 151 return IsValidBookmarkAppUrl(web_contents()->GetURL()); |
155 #endif | |
156 } | 152 } |
157 | 153 |
158 void TabHelper::AddScriptExecutionObserver(ScriptExecutionObserver* observer) { | 154 void TabHelper::AddScriptExecutionObserver(ScriptExecutionObserver* observer) { |
159 script_execution_observers_.AddObserver(observer); | 155 script_execution_observers_.AddObserver(observer); |
160 } | 156 } |
161 | 157 |
162 void TabHelper::RemoveScriptExecutionObserver( | 158 void TabHelper::RemoveScriptExecutionObserver( |
163 ScriptExecutionObserver* observer) { | 159 ScriptExecutionObserver* observer) { |
164 script_execution_observers_.RemoveObserver(observer); | 160 script_execution_observers_.RemoveObserver(observer); |
165 } | 161 } |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
288 // When the WebContents that this is attached to is cloned, give the new clone | 284 // When the WebContents that this is attached to is cloned, give the new clone |
289 // a TabHelper and copy state over. | 285 // a TabHelper and copy state over. |
290 CreateForWebContents(new_web_contents); | 286 CreateForWebContents(new_web_contents); |
291 TabHelper* new_helper = FromWebContents(new_web_contents); | 287 TabHelper* new_helper = FromWebContents(new_web_contents); |
292 | 288 |
293 new_helper->SetExtensionApp(extension_app()); | 289 new_helper->SetExtensionApp(extension_app()); |
294 new_helper->extension_app_icon_ = extension_app_icon_; | 290 new_helper->extension_app_icon_ = extension_app_icon_; |
295 } | 291 } |
296 | 292 |
297 void TabHelper::OnDidGetWebApplicationInfo(const WebApplicationInfo& info) { | 293 void TabHelper::OnDidGetWebApplicationInfo(const WebApplicationInfo& info) { |
298 #if !defined(OS_MACOSX) | |
299 web_app_info_ = info; | 294 web_app_info_ = info; |
300 | 295 |
301 NavigationEntry* entry = | 296 NavigationEntry* entry = |
302 web_contents()->GetController().GetLastCommittedEntry(); | 297 web_contents()->GetController().GetLastCommittedEntry(); |
303 if (!entry || last_committed_page_id_ != entry->GetPageID()) | 298 if (!entry || last_committed_page_id_ != entry->GetPageID()) |
304 return; | 299 return; |
305 last_committed_page_id_ = -1; | 300 last_committed_page_id_ = -1; |
306 | 301 |
307 switch (pending_web_app_action_) { | 302 switch (pending_web_app_action_) { |
303 #if !defined(OS_MACOSX) | |
308 case CREATE_SHORTCUT: { | 304 case CREATE_SHORTCUT: { |
309 chrome::ShowCreateWebAppShortcutsDialog( | 305 chrome::ShowCreateWebAppShortcutsDialog( |
310 web_contents()->GetTopLevelNativeWindow(), | 306 web_contents()->GetTopLevelNativeWindow(), |
311 web_contents()); | 307 web_contents()); |
312 break; | 308 break; |
313 } | 309 } |
310 #endif | |
314 case CREATE_HOSTED_APP: { | 311 case CREATE_HOSTED_APP: { |
315 if (web_app_info_.app_url.is_empty()) | 312 if (web_app_info_.app_url.is_empty()) |
316 web_app_info_.app_url = web_contents()->GetURL(); | 313 web_app_info_.app_url = web_contents()->GetURL(); |
317 | 314 |
318 if (web_app_info_.title.empty()) | 315 if (web_app_info_.title.empty()) |
319 web_app_info_.title = web_contents()->GetTitle(); | 316 web_app_info_.title = web_contents()->GetTitle(); |
320 if (web_app_info_.title.empty()) | 317 if (web_app_info_.title.empty()) |
321 web_app_info_.title = base::UTF8ToUTF16(web_app_info_.app_url.spec()); | 318 web_app_info_.title = base::UTF8ToUTF16(web_app_info_.app_url.spec()); |
322 | 319 |
323 bookmark_app_helper_.reset(new BookmarkAppHelper( | 320 bookmark_app_helper_.reset(new BookmarkAppHelper( |
324 ExtensionSystem::Get(profile_)->extension_service(), | 321 ExtensionSystem::Get(profile_)->extension_service(), |
325 web_app_info_, web_contents())); | 322 web_app_info_, web_contents())); |
326 bookmark_app_helper_->Create(base::Bind( | 323 bookmark_app_helper_->Create(base::Bind( |
327 &TabHelper::FinishCreateBookmarkApp, weak_ptr_factory_.GetWeakPtr())); | 324 &TabHelper::FinishCreateBookmarkApp, weak_ptr_factory_.GetWeakPtr())); |
328 break; | 325 break; |
329 } | 326 } |
330 case UPDATE_SHORTCUT: { | 327 case UPDATE_SHORTCUT: { |
331 web_app::UpdateShortcutForTabContents(web_contents()); | 328 web_app::UpdateShortcutForTabContents(web_contents()); |
332 break; | 329 break; |
333 } | 330 } |
334 default: | 331 default: |
335 NOTREACHED(); | 332 NOTREACHED(); |
sky
2014/12/01 17:21:02
Is it nos possible to end up here on a mac if pend
| |
336 break; | 333 break; |
337 } | 334 } |
338 | 335 |
339 // The hosted app action will be cleared once the installation completes or | 336 // The hosted app action will be cleared once the installation completes or |
340 // fails. | 337 // fails. |
341 if (pending_web_app_action_ != CREATE_HOSTED_APP) | 338 if (pending_web_app_action_ != CREATE_HOSTED_APP) |
342 pending_web_app_action_ = NONE; | 339 pending_web_app_action_ = NONE; |
343 #endif | |
344 } | 340 } |
345 | 341 |
346 void TabHelper::OnInlineWebstoreInstall(int install_id, | 342 void TabHelper::OnInlineWebstoreInstall(int install_id, |
347 int return_route_id, | 343 int return_route_id, |
348 const std::string& webstore_item_id, | 344 const std::string& webstore_item_id, |
349 const GURL& requestor_url, | 345 const GURL& requestor_url, |
350 int listeners_mask) { | 346 int listeners_mask) { |
351 // Check that the listener is reasonable. We should never get anything other | 347 // Check that the listener is reasonable. We should never get anything other |
352 // than an install stage listener, a download listener, or both. | 348 // than an install stage listener, a download listener, or both. |
353 if ((listeners_mask & ~(api::webstore::INSTALL_STAGE_LISTENER | | 349 if ((listeners_mask & ~(api::webstore::INSTALL_STAGE_LISTENER | |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
597 } | 593 } |
598 } | 594 } |
599 | 595 |
600 void TabHelper::SetTabId(RenderViewHost* render_view_host) { | 596 void TabHelper::SetTabId(RenderViewHost* render_view_host) { |
601 render_view_host->Send( | 597 render_view_host->Send( |
602 new ExtensionMsg_SetTabId(render_view_host->GetRoutingID(), | 598 new ExtensionMsg_SetTabId(render_view_host->GetRoutingID(), |
603 SessionTabHelper::IdForTab(web_contents()))); | 599 SessionTabHelper::IdForTab(web_contents()))); |
604 } | 600 } |
605 | 601 |
606 } // namespace extensions | 602 } // namespace extensions |
OLD | NEW |