OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extension_tabs_module.h" | 5 #include "chrome/browser/extensions/extension_tabs_module.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/sessions/restore_tab_helper.h" | 24 #include "chrome/browser/sessions/restore_tab_helper.h" |
25 #include "chrome/browser/tabs/tab_strip_model.h" | 25 #include "chrome/browser/tabs/tab_strip_model.h" |
26 #include "chrome/browser/translate/translate_tab_helper.h" | 26 #include "chrome/browser/translate/translate_tab_helper.h" |
27 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
28 #include "chrome/browser/ui/browser_list.h" | 28 #include "chrome/browser/ui/browser_list.h" |
29 #include "chrome/browser/ui/browser_navigator.h" | 29 #include "chrome/browser/ui/browser_navigator.h" |
30 #include "chrome/browser/ui/browser_window.h" | 30 #include "chrome/browser/ui/browser_window.h" |
31 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 31 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
32 #include "chrome/browser/ui/window_sizer.h" | 32 #include "chrome/browser/ui/window_sizer.h" |
| 33 #include "chrome/browser/web_applications/web_app.h" |
33 #include "chrome/common/chrome_notification_types.h" | 34 #include "chrome/common/chrome_notification_types.h" |
34 #include "chrome/common/chrome_switches.h" | 35 #include "chrome/common/chrome_switches.h" |
35 #include "chrome/common/extensions/extension.h" | 36 #include "chrome/common/extensions/extension.h" |
36 #include "chrome/common/extensions/extension_error_utils.h" | 37 #include "chrome/common/extensions/extension_error_utils.h" |
37 #include "chrome/common/extensions/extension_messages.h" | 38 #include "chrome/common/extensions/extension_messages.h" |
38 #include "chrome/common/pref_names.h" | 39 #include "chrome/common/pref_names.h" |
39 #include "chrome/common/url_constants.h" | 40 #include "chrome/common/url_constants.h" |
40 #include "content/browser/renderer_host/backing_store.h" | 41 #include "content/browser/renderer_host/backing_store.h" |
41 #include "content/browser/renderer_host/render_view_host.h" | 42 #include "content/browser/renderer_host/render_view_host.h" |
42 #include "content/browser/renderer_host/render_view_host_delegate.h" | 43 #include "content/browser/renderer_host/render_view_host_delegate.h" |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 // bounds as windows. | 489 // bounds as windows. |
489 #if defined(OS_CHROMEOS) | 490 #if defined(OS_CHROMEOS) |
490 popup_bounds = panel_bounds; | 491 popup_bounds = panel_bounds; |
491 #else | 492 #else |
492 popup_bounds = window_bounds; // Use window size as default for popups | 493 popup_bounds = window_bounds; // Use window size as default for popups |
493 #endif | 494 #endif |
494 | 495 |
495 Profile* window_profile = profile(); | 496 Profile* window_profile = profile(); |
496 Browser::Type window_type = Browser::TYPE_TABBED; | 497 Browser::Type window_type = Browser::TYPE_TABBED; |
497 bool focused = true; | 498 bool focused = true; |
498 std::string app_name; | 499 std::string extension_id; |
499 | 500 |
500 if (args) { | 501 if (args) { |
501 // Any part of the bounds can optionally be set by the caller. | 502 // Any part of the bounds can optionally be set by the caller. |
502 int bounds_val; | 503 int bounds_val; |
503 if (args->HasKey(keys::kLeftKey)) { | 504 if (args->HasKey(keys::kLeftKey)) { |
504 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kLeftKey, | 505 EXTENSION_FUNCTION_VALIDATE(args->GetInteger(keys::kLeftKey, |
505 &bounds_val)); | 506 &bounds_val)); |
506 window_bounds.set_x(bounds_val); | 507 window_bounds.set_x(bounds_val); |
507 popup_bounds.set_x(bounds_val); | 508 popup_bounds.set_x(bounds_val); |
508 panel_bounds.set_x(bounds_val); | 509 panel_bounds.set_x(bounds_val); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 if (args->HasKey(keys::kFocusedKey)) | 550 if (args->HasKey(keys::kFocusedKey)) |
550 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kFocusedKey, | 551 EXTENSION_FUNCTION_VALIDATE(args->GetBoolean(keys::kFocusedKey, |
551 &focused)); | 552 &focused)); |
552 | 553 |
553 std::string type_str; | 554 std::string type_str; |
554 if (args->HasKey(keys::kWindowTypeKey)) { | 555 if (args->HasKey(keys::kWindowTypeKey)) { |
555 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kWindowTypeKey, | 556 EXTENSION_FUNCTION_VALIDATE(args->GetString(keys::kWindowTypeKey, |
556 &type_str)); | 557 &type_str)); |
557 if (type_str == keys::kWindowTypeValuePopup) { | 558 if (type_str == keys::kWindowTypeValuePopup) { |
558 window_type = Browser::TYPE_POPUP; | 559 window_type = Browser::TYPE_POPUP; |
559 app_name = GetExtension()->id(); | 560 extension_id = GetExtension()->id(); |
560 } else if (type_str == keys::kWindowTypeValuePanel) { | 561 } else if (type_str == keys::kWindowTypeValuePanel) { |
561 if (GetExtension()->HasAPIPermission( | 562 if (GetExtension()->HasAPIPermission( |
562 ExtensionAPIPermission::kExperimental)) { | 563 ExtensionAPIPermission::kExperimental)) { |
563 window_type = Browser::TYPE_PANEL; | 564 window_type = Browser::TYPE_PANEL; |
564 app_name = GetExtension()->id(); | 565 extension_id = GetExtension()->id(); |
565 } else { | 566 } else { |
566 error_ = errors::kExperimentalFeature; | 567 error_ = errors::kExperimentalFeature; |
567 return false; | 568 return false; |
568 } | 569 } |
569 } else if (type_str != keys::kWindowTypeValueNormal) { | 570 } else if (type_str != keys::kWindowTypeValueNormal) { |
570 EXTENSION_FUNCTION_VALIDATE(false); | 571 EXTENSION_FUNCTION_VALIDATE(false); |
571 } | 572 } |
572 } | 573 } |
573 } | 574 } |
574 | 575 |
575 Browser* new_window; | 576 Browser* new_window; |
576 if (app_name.empty()) { | 577 if (extension_id.empty()) { |
577 new_window = Browser::CreateForType(window_type, window_profile); | 578 new_window = Browser::CreateForType(window_type, window_profile); |
578 new_window->window()->SetBounds(window_bounds); | 579 new_window->window()->SetBounds(window_bounds); |
579 } else { | 580 } else { |
580 new_window = Browser::CreateForApp( | 581 new_window = Browser::CreateForApp( |
581 window_type, app_name, | 582 window_type, |
| 583 web_app::GenerateApplicationNameFromExtensionId(extension_id), |
582 (window_type == Browser::TYPE_PANEL ? panel_bounds : popup_bounds), | 584 (window_type == Browser::TYPE_PANEL ? panel_bounds : popup_bounds), |
583 window_profile); | 585 window_profile); |
584 } | 586 } |
585 for (std::vector<GURL>::iterator i = urls.begin(); i != urls.end(); ++i) | 587 for (std::vector<GURL>::iterator i = urls.begin(); i != urls.end(); ++i) |
586 new_window->AddSelectedTabWithURL(*i, PageTransition::LINK); | 588 new_window->AddSelectedTabWithURL(*i, PageTransition::LINK); |
587 if (contents) { | 589 if (contents) { |
588 TabStripModel* target_tab_strip = new_window->tabstrip_model(); | 590 TabStripModel* target_tab_strip = new_window->tabstrip_model(); |
589 target_tab_strip->InsertTabContentsAt(urls.size(), contents, | 591 target_tab_strip->InsertTabContentsAt(urls.size(), contents, |
590 TabStripModel::ADD_NONE); | 592 TabStripModel::ADD_NONE); |
591 } else if (urls.empty()) { | 593 } else if (urls.empty()) { |
(...skipping 848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1440 // called for every API call the extension made. | 1442 // called for every API call the extension made. |
1441 GotLanguage(language); | 1443 GotLanguage(language); |
1442 } | 1444 } |
1443 | 1445 |
1444 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { | 1446 void DetectTabLanguageFunction::GotLanguage(const std::string& language) { |
1445 result_.reset(Value::CreateStringValue(language.c_str())); | 1447 result_.reset(Value::CreateStringValue(language.c_str())); |
1446 SendResponse(true); | 1448 SendResponse(true); |
1447 | 1449 |
1448 Release(); // Balanced in Run() | 1450 Release(); // Balanced in Run() |
1449 } | 1451 } |
OLD | NEW |