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

Side by Side Diff: chrome/browser/extensions/extension_tabs_module.cc

Issue 4694008: Make pink's TabContentsWrapper change compile on Windows.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "base/base64.h" 7 #include "base/base64.h"
8 #include "base/string_number_conversions.h" 8 #include "base/string_number_conversions.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "chrome/browser/browser_list.h" 12 #include "chrome/browser/browser_list.h"
13 #include "chrome/browser/browser_window.h" 13 #include "chrome/browser/browser_window.h"
14 #include "chrome/browser/extensions/extension_function_dispatcher.h" 14 #include "chrome/browser/extensions/extension_function_dispatcher.h"
15 #include "chrome/browser/extensions/extension_host.h" 15 #include "chrome/browser/extensions/extension_host.h"
16 #include "chrome/browser/extensions/extension_infobar_delegate.h" 16 #include "chrome/browser/extensions/extension_infobar_delegate.h"
17 #include "chrome/browser/extensions/extension_tabs_module_constants.h" 17 #include "chrome/browser/extensions/extension_tabs_module_constants.h"
18 #include "chrome/browser/extensions/extensions_service.h" 18 #include "chrome/browser/extensions/extensions_service.h"
19 #include "chrome/browser/profile.h" 19 #include "chrome/browser/profile.h"
20 #include "chrome/browser/renderer_host/backing_store.h" 20 #include "chrome/browser/renderer_host/backing_store.h"
21 #include "chrome/browser/renderer_host/render_view_host.h" 21 #include "chrome/browser/renderer_host/render_view_host.h"
22 #include "chrome/browser/renderer_host/render_view_host_delegate.h" 22 #include "chrome/browser/renderer_host/render_view_host_delegate.h"
23 #include "chrome/browser/tab_contents/navigation_entry.h" 23 #include "chrome/browser/tab_contents/navigation_entry.h"
24 #include "chrome/browser/tab_contents/tab_contents_view.h" 24 #include "chrome/browser/tab_contents/tab_contents_view.h"
25 #include "chrome/browser/tab_contents/tab_contents.h" 25 #include "chrome/browser/tab_contents/tab_contents.h"
26 #include "chrome/browser/tab_contents_wrapper.h"
26 #include "chrome/browser/tabs/tab_strip_model.h" 27 #include "chrome/browser/tabs/tab_strip_model.h"
27 #include "chrome/browser/ui/browser.h" 28 #include "chrome/browser/ui/browser.h"
28 #include "chrome/browser/ui/browser_navigator.h" 29 #include "chrome/browser/ui/browser_navigator.h"
29 #include "chrome/browser/window_sizer.h" 30 #include "chrome/browser/window_sizer.h"
30 #include "chrome/common/extensions/extension.h" 31 #include "chrome/common/extensions/extension.h"
31 #include "chrome/common/extensions/extension_error_utils.h" 32 #include "chrome/common/extensions/extension_error_utils.h"
32 #include "chrome/common/url_constants.h" 33 #include "chrome/common/url_constants.h"
33 #include "gfx/codec/jpeg_codec.h" 34 #include "gfx/codec/jpeg_codec.h"
34 #include "gfx/codec/png_codec.h" 35 #include "gfx/codec/png_codec.h"
35 #include "skia/ext/image_operations.h" 36 #include "skia/ext/image_operations.h"
(...skipping 12 matching lines...) Expand all
48 const int window_id, 49 const int window_id,
49 bool include_incognito, 50 bool include_incognito,
50 std::string* error_message); 51 std::string* error_message);
51 52
52 // |error_message| can optionally be passed in and will be set with an 53 // |error_message| can optionally be passed in and will be set with an
53 // appropriate message if the tab cannot be found by id. 54 // appropriate message if the tab cannot be found by id.
54 static bool GetTabById(int tab_id, Profile* profile, 55 static bool GetTabById(int tab_id, Profile* profile,
55 bool include_incognito, 56 bool include_incognito,
56 Browser** browser, 57 Browser** browser,
57 TabStripModel** tab_strip, 58 TabStripModel** tab_strip,
58 TabContents** contents, 59 TabContentsWrapper** contents,
59 int* tab_index, std::string* error_message); 60 int* tab_index, std::string* error_message);
60 61
61 // Takes |url_string| and returns a GURL which is either valid and absolute 62 // Takes |url_string| and returns a GURL which is either valid and absolute
62 // or invalid. If |url_string| is not directly interpretable as a valid (it is 63 // or invalid. If |url_string| is not directly interpretable as a valid (it is
63 // likely a relative URL) an attempt is made to resolve it. |extension| is 64 // likely a relative URL) an attempt is made to resolve it. |extension| is
64 // provided so it can be resolved relative to its extension base 65 // provided so it can be resolved relative to its extension base
65 // (chrome-extension://<id>/). Using the source frame url would be more correct, 66 // (chrome-extension://<id>/). Using the source frame url would be more correct,
66 // but because the api shipped with urls resolved relative to their extension 67 // but because the api shipped with urls resolved relative to their extension
67 // base, we decided it wasn't worth breaking existing extensions to fix. 68 // base, we decided it wasn't worth breaking existing extensions to fix.
68 static GURL ResolvePossiblyRelativeURL(std::string url_string, 69 static GURL ResolvePossiblyRelativeURL(std::string url_string,
(...skipping 28 matching lines...) Expand all
97 98
98 // Couldn't find it. This can happen if the tab is being dragged. 99 // Couldn't find it. This can happen if the tab is being dragged.
99 return ExtensionTabUtil::CreateTabValue(contents, NULL, -1); 100 return ExtensionTabUtil::CreateTabValue(contents, NULL, -1);
100 } 101 }
101 102
102 ListValue* ExtensionTabUtil::CreateTabList(const Browser* browser) { 103 ListValue* ExtensionTabUtil::CreateTabList(const Browser* browser) {
103 ListValue* tab_list = new ListValue(); 104 ListValue* tab_list = new ListValue();
104 TabStripModel* tab_strip = browser->tabstrip_model(); 105 TabStripModel* tab_strip = browser->tabstrip_model();
105 for (int i = 0; i < tab_strip->count(); ++i) { 106 for (int i = 0; i < tab_strip->count(); ++i) {
106 tab_list->Append(ExtensionTabUtil::CreateTabValue( 107 tab_list->Append(ExtensionTabUtil::CreateTabValue(
107 tab_strip->GetTabContentsAt(i), tab_strip, i)); 108 tab_strip->GetTabContentsAt(i)->tab_contents(), tab_strip, i));
108 } 109 }
109 110
110 return tab_list; 111 return tab_list;
111 } 112 }
112 113
113 DictionaryValue* ExtensionTabUtil::CreateTabValue( 114 DictionaryValue* ExtensionTabUtil::CreateTabValue(
114 const TabContents* contents, TabStripModel* tab_strip, int tab_index) { 115 const TabContents* contents, TabStripModel* tab_strip, int tab_index) {
115 DictionaryValue* result = new DictionaryValue(); 116 DictionaryValue* result = new DictionaryValue();
116 result->SetInteger(keys::kIdKey, ExtensionTabUtil::GetTabId(contents)); 117 result->SetInteger(keys::kIdKey, ExtensionTabUtil::GetTabId(contents));
117 result->SetInteger(keys::kIndexKey, tab_index); 118 result->SetInteger(keys::kIndexKey, tab_index);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 bool ExtensionTabUtil::GetTabStripModel(const TabContents* tab_contents, 168 bool ExtensionTabUtil::GetTabStripModel(const TabContents* tab_contents,
168 TabStripModel** tab_strip_model, 169 TabStripModel** tab_strip_model,
169 int* tab_index) { 170 int* tab_index) {
170 DCHECK(tab_contents); 171 DCHECK(tab_contents);
171 DCHECK(tab_strip_model); 172 DCHECK(tab_strip_model);
172 DCHECK(tab_index); 173 DCHECK(tab_index);
173 174
174 for (BrowserList::const_iterator it = BrowserList::begin(); 175 for (BrowserList::const_iterator it = BrowserList::begin();
175 it != BrowserList::end(); ++it) { 176 it != BrowserList::end(); ++it) {
176 TabStripModel* tab_strip = (*it)->tabstrip_model(); 177 TabStripModel* tab_strip = (*it)->tabstrip_model();
177 int index = tab_strip->GetIndexOfTabContents(tab_contents); 178 int index = tab_strip->GetWrapperIndex(tab_contents);
178 if (index != -1) { 179 if (index != -1) {
179 *tab_strip_model = tab_strip; 180 *tab_strip_model = tab_strip;
180 *tab_index = index; 181 *tab_index = index;
181 return true; 182 return true;
182 } 183 }
183 } 184 }
184 185
185 return false; 186 return false;
186 } 187 }
187 188
188 bool ExtensionTabUtil::GetDefaultTab(Browser* browser, TabContents** contents, 189 bool ExtensionTabUtil::GetDefaultTab(Browser* browser,
190 TabContentsWrapper** contents,
189 int* tab_id) { 191 int* tab_id) {
190 DCHECK(browser); 192 DCHECK(browser);
191 DCHECK(contents); 193 DCHECK(contents);
192 DCHECK(tab_id); 194 DCHECK(tab_id);
193 195
194 *contents = browser->tabstrip_model()->GetSelectedTabContents(); 196 *contents = browser->GetSelectedTabContentsWrapper();
195 if (*contents) { 197 if (*contents) {
196 if (tab_id) 198 if (tab_id)
197 *tab_id = ExtensionTabUtil::GetTabId(*contents); 199 *tab_id = ExtensionTabUtil::GetTabId((*contents)->tab_contents());
198 return true; 200 return true;
199 } 201 }
200 202
201 return false; 203 return false;
202 } 204 }
203 205
204 bool ExtensionTabUtil::GetTabById(int tab_id, Profile* profile, 206 bool ExtensionTabUtil::GetTabById(int tab_id, Profile* profile,
205 bool include_incognito, 207 bool include_incognito,
206 Browser** browser, 208 Browser** browser,
207 TabStripModel** tab_strip, 209 TabStripModel** tab_strip,
208 TabContents** contents, 210 TabContentsWrapper** contents,
209 int* tab_index) { 211 int* tab_index) {
210 Browser* target_browser;
211 TabStripModel* target_tab_strip;
212 TabContents* target_contents;
213 Profile* incognito_profile = 212 Profile* incognito_profile =
214 include_incognito && profile->HasOffTheRecordProfile() ? 213 include_incognito && profile->HasOffTheRecordProfile() ?
215 profile->GetOffTheRecordProfile() : NULL; 214 profile->GetOffTheRecordProfile() : NULL;
216 for (BrowserList::const_iterator iter = BrowserList::begin(); 215 for (BrowserList::const_iterator iter = BrowserList::begin();
217 iter != BrowserList::end(); ++iter) { 216 iter != BrowserList::end(); ++iter) {
218 target_browser = *iter; 217 Browser* target_browser = *iter;
219 if (target_browser->profile() == profile || 218 if (target_browser->profile() == profile ||
220 target_browser->profile() == incognito_profile) { 219 target_browser->profile() == incognito_profile) {
221 target_tab_strip = target_browser->tabstrip_model(); 220 TabStripModel* target_tab_strip = target_browser->tabstrip_model();
222 for (int i = 0; i < target_tab_strip->count(); ++i) { 221 for (int i = 0; i < target_tab_strip->count(); ++i) {
223 target_contents = target_tab_strip->GetTabContentsAt(i); 222 TabContentsWrapper* target_contents =
223 target_tab_strip->GetTabContentsAt(i);
224 if (target_contents->controller().session_id().id() == tab_id) { 224 if (target_contents->controller().session_id().id() == tab_id) {
225 if (browser) 225 if (browser)
226 *browser = target_browser; 226 *browser = target_browser;
227 if (tab_strip) 227 if (tab_strip)
228 *tab_strip = target_tab_strip; 228 *tab_strip = target_tab_strip;
229 if (contents) 229 if (contents)
230 *contents = target_contents; 230 *contents = target_contents;
231 if (tab_index) 231 if (tab_index)
232 *tab_index = i; 232 *tab_index = i;
233 return true; 233 return true;
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 include_incognito(), &error_); 535 include_incognito(), &error_);
536 } else { 536 } else {
537 browser = GetCurrentBrowser(); 537 browser = GetCurrentBrowser();
538 if (!browser) 538 if (!browser)
539 error_ = keys::kNoCurrentWindowError; 539 error_ = keys::kNoCurrentWindowError;
540 } 540 }
541 if (!browser) 541 if (!browser)
542 return false; 542 return false;
543 543
544 TabStripModel* tab_strip = browser->tabstrip_model(); 544 TabStripModel* tab_strip = browser->tabstrip_model();
545 TabContents* contents = tab_strip->GetSelectedTabContents(); 545 TabContentsWrapper* contents = tab_strip->GetSelectedTabContents();
546 if (!contents) { 546 if (!contents) {
547 error_ = keys::kNoSelectedTabError; 547 error_ = keys::kNoSelectedTabError;
548 return false; 548 return false;
549 } 549 }
550 result_.reset(ExtensionTabUtil::CreateTabValue(contents, tab_strip, 550 result_.reset(ExtensionTabUtil::CreateTabValue(contents->tab_contents(),
551 tab_strip,
551 tab_strip->selected_index())); 552 tab_strip->selected_index()));
552 return true; 553 return true;
553 } 554 }
554 555
555 bool GetAllTabsInWindowFunction::RunImpl() { 556 bool GetAllTabsInWindowFunction::RunImpl() {
556 Browser* browser; 557 Browser* browser;
557 // windowId defaults to "current" window. 558 // windowId defaults to "current" window.
558 int window_id = -1; 559 int window_id = -1;
559 if (HasOptionalArgument(0)) { 560 if (HasOptionalArgument(0)) {
560 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id)); 561 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &window_id));
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 params.tabstrip_index = index; 658 params.tabstrip_index = index;
658 params.tabstrip_add_types = add_types; 659 params.tabstrip_add_types = add_types;
659 browser::Navigate(&params); 660 browser::Navigate(&params);
660 661
661 if (selected) 662 if (selected)
662 params.target_contents->view()->SetInitialFocus(); 663 params.target_contents->view()->SetInitialFocus();
663 664
664 // Return data about the newly created tab. 665 // Return data about the newly created tab.
665 if (has_callback()) { 666 if (has_callback()) {
666 result_.reset(ExtensionTabUtil::CreateTabValue( 667 result_.reset(ExtensionTabUtil::CreateTabValue(
667 params.target_contents, 668 params.target_contents->tab_contents(),
668 params.browser->tabstrip_model(), 669 params.browser->tabstrip_model(),
669 params.browser->tabstrip_model()->GetIndexOfTabContents( 670 params.browser->tabstrip_model()->GetIndexOfTabContents(
670 params.target_contents))); 671 params.target_contents)));
671 } 672 }
672 673
673 return true; 674 return true;
674 } 675 }
675 676
676 bool GetTabFunction::RunImpl() { 677 bool GetTabFunction::RunImpl() {
677 int tab_id; 678 int tab_id;
678 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); 679 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id));
679 680
680 TabStripModel* tab_strip = NULL; 681 TabStripModel* tab_strip = NULL;
681 TabContents* contents = NULL; 682 TabContentsWrapper* contents = NULL;
682 int tab_index = -1; 683 int tab_index = -1;
683 if (!GetTabById(tab_id, profile(), include_incognito(), 684 if (!GetTabById(tab_id, profile(), include_incognito(),
684 NULL, &tab_strip, &contents, &tab_index, &error_)) 685 NULL, &tab_strip, &contents, &tab_index, &error_))
685 return false; 686 return false;
686 687
687 result_.reset(ExtensionTabUtil::CreateTabValue(contents, tab_strip, 688 result_.reset(ExtensionTabUtil::CreateTabValue(contents->tab_contents(),
689 tab_strip,
688 tab_index)); 690 tab_index));
689 return true; 691 return true;
690 } 692 }
691 693
692 bool GetCurrentTabFunction::RunImpl() { 694 bool GetCurrentTabFunction::RunImpl() {
693 DCHECK(dispatcher()); 695 DCHECK(dispatcher());
694 696
695 TabContents* contents = dispatcher()->delegate()->associated_tab_contents(); 697 TabContents* contents = dispatcher()->delegate()->associated_tab_contents();
696 if (contents) 698 if (contents)
697 result_.reset(ExtensionTabUtil::CreateTabValue(contents)); 699 result_.reset(ExtensionTabUtil::CreateTabValue(contents));
698 700
699 return true; 701 return true;
700 } 702 }
701 703
702 bool UpdateTabFunction::RunImpl() { 704 bool UpdateTabFunction::RunImpl() {
703 int tab_id; 705 int tab_id;
704 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); 706 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id));
705 DictionaryValue* update_props; 707 DictionaryValue* update_props;
706 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); 708 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props));
707 709
708 TabStripModel* tab_strip = NULL; 710 TabStripModel* tab_strip = NULL;
709 TabContents* contents = NULL; 711 TabContentsWrapper* contents = NULL;
710 int tab_index = -1; 712 int tab_index = -1;
711 if (!GetTabById(tab_id, profile(), include_incognito(), 713 if (!GetTabById(tab_id, profile(), include_incognito(),
712 NULL, &tab_strip, &contents, &tab_index, &error_)) 714 NULL, &tab_strip, &contents, &tab_index, &error_))
713 return false; 715 return false;
714 716
715 NavigationController& controller = contents->controller(); 717 NavigationController& controller = contents->controller();
716 718
717 // TODO(rafaelw): handle setting remaining tab properties: 719 // TODO(rafaelw): handle setting remaining tab properties:
718 // -title 720 // -title
719 // -favIconUrl 721 // -favIconUrl
(...skipping 11 matching lines...) Expand all
731 return false; 733 return false;
732 } 734 }
733 735
734 // JavaScript URLs can do the same kinds of things as cross-origin XHR, so 736 // JavaScript URLs can do the same kinds of things as cross-origin XHR, so
735 // we need to check host permissions before allowing them. 737 // we need to check host permissions before allowing them.
736 if (url.SchemeIs(chrome::kJavaScriptScheme)) { 738 if (url.SchemeIs(chrome::kJavaScriptScheme)) {
737 const Extension* extension = GetExtension(); 739 const Extension* extension = GetExtension();
738 const std::vector<URLPattern> host_permissions = 740 const std::vector<URLPattern> host_permissions =
739 extension->host_permissions(); 741 extension->host_permissions();
740 if (!Extension::CanExecuteScriptOnPage( 742 if (!Extension::CanExecuteScriptOnPage(
741 contents->GetURL(), 743 contents->tab_contents()->GetURL(),
742 extension->CanExecuteScriptEverywhere(), 744 extension->CanExecuteScriptEverywhere(),
743 &host_permissions, 745 &host_permissions,
744 NULL, 746 NULL,
745 &error_)) { 747 &error_)) {
746 return false; 748 return false;
747 } 749 }
748 750
749 // TODO(aa): How does controller queue URLs? Is there any chance that this 751 // TODO(aa): How does controller queue URLs? Is there any chance that this
750 // JavaScript URL will end up applying to something other than 752 // JavaScript URL will end up applying to something other than
751 // controller->GetURL()? 753 // controller->GetURL()?
752 } 754 }
753 755
754 controller.LoadURL(url, GURL(), PageTransition::LINK); 756 controller.LoadURL(url, GURL(), PageTransition::LINK);
755 757
756 // The URL of a tab contents never actually changes to a JavaScript URL, so 758 // The URL of a tab contents never actually changes to a JavaScript URL, so
757 // this check only makes sense in other cases. 759 // this check only makes sense in other cases.
758 if (!url.SchemeIs(chrome::kJavaScriptScheme)) 760 if (!url.SchemeIs(chrome::kJavaScriptScheme))
759 DCHECK_EQ(url.spec(), contents->GetURL().spec()); 761 DCHECK_EQ(url.spec(), contents->tab_contents()->GetURL().spec());
760 } 762 }
761 763
762 bool selected = false; 764 bool selected = false;
763 // TODO(rafaelw): Setting |selected| from js doesn't make much sense. 765 // TODO(rafaelw): Setting |selected| from js doesn't make much sense.
764 // Move tab selection management up to window. 766 // Move tab selection management up to window.
765 if (update_props->HasKey(keys::kSelectedKey)) { 767 if (update_props->HasKey(keys::kSelectedKey)) {
766 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean( 768 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean(
767 keys::kSelectedKey, 769 keys::kSelectedKey,
768 &selected)); 770 &selected));
769 if (selected) { 771 if (selected) {
770 if (tab_strip->selected_index() != tab_index) { 772 if (tab_strip->selected_index() != tab_index) {
771 tab_strip->SelectTabContentsAt(tab_index, false); 773 tab_strip->SelectTabContentsAt(tab_index, false);
772 DCHECK_EQ(contents, tab_strip->GetSelectedTabContents()); 774 DCHECK_EQ(contents, tab_strip->GetSelectedTabContents());
773 } 775 }
774 contents->Focus(); 776 contents->tab_contents()->Focus();
775 } 777 }
776 } 778 }
777 779
778 bool pinned = false; 780 bool pinned = false;
779 if (update_props->HasKey(keys::kPinnedKey)) { 781 if (update_props->HasKey(keys::kPinnedKey)) {
780 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean(keys::kPinnedKey, 782 EXTENSION_FUNCTION_VALIDATE(update_props->GetBoolean(keys::kPinnedKey,
781 &pinned)); 783 &pinned));
782 tab_strip->SetTabPinned(tab_index, pinned); 784 tab_strip->SetTabPinned(tab_index, pinned);
783 785
784 // Update the tab index because it may move when being pinned. 786 // Update the tab index because it may move when being pinned.
785 tab_index = tab_strip->GetIndexOfTabContents(contents); 787 tab_index = tab_strip->GetIndexOfTabContents(contents);
786 } 788 }
787 789
788 if (has_callback()) 790 if (has_callback())
789 result_.reset(ExtensionTabUtil::CreateTabValue(contents, tab_strip, 791 result_.reset(ExtensionTabUtil::CreateTabValue(contents->tab_contents(),
792 tab_strip,
790 tab_index)); 793 tab_index));
791 794
792 return true; 795 return true;
793 } 796 }
794 797
795 bool MoveTabFunction::RunImpl() { 798 bool MoveTabFunction::RunImpl() {
796 int tab_id; 799 int tab_id;
797 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); 800 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id));
798 DictionaryValue* update_props; 801 DictionaryValue* update_props;
799 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props)); 802 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &update_props));
800 803
801 int new_index; 804 int new_index;
802 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger( 805 EXTENSION_FUNCTION_VALIDATE(update_props->GetInteger(
803 keys::kIndexKey, &new_index)); 806 keys::kIndexKey, &new_index));
804 EXTENSION_FUNCTION_VALIDATE(new_index >= 0); 807 EXTENSION_FUNCTION_VALIDATE(new_index >= 0);
805 808
806 Browser* source_browser = NULL; 809 Browser* source_browser = NULL;
807 TabStripModel* source_tab_strip = NULL; 810 TabStripModel* source_tab_strip = NULL;
808 TabContents* contents = NULL; 811 TabContentsWrapper* contents = NULL;
809 int tab_index = -1; 812 int tab_index = -1;
810 if (!GetTabById(tab_id, profile(), include_incognito(), 813 if (!GetTabById(tab_id, profile(), include_incognito(),
811 &source_browser, &source_tab_strip, &contents, 814 &source_browser, &source_tab_strip, &contents,
812 &tab_index, &error_)) 815 &tab_index, &error_))
813 return false; 816 return false;
814 817
815 if (source_browser->type() != Browser::TYPE_NORMAL) { 818 if (source_browser->type() != Browser::TYPE_NORMAL) {
816 error_ = keys::kCanOnlyMoveTabsWithinNormalWindowsError; 819 error_ = keys::kCanOnlyMoveTabsWithinNormalWindowsError;
817 return false; 820 return false;
818 } 821 }
(...skipping 26 matching lines...) Expand all
845 848
846 // Clamp move location to the last position. 849 // Clamp move location to the last position.
847 // This is ">" because it can append to a new index position. 850 // This is ">" because it can append to a new index position.
848 if (new_index > target_tab_strip->count()) 851 if (new_index > target_tab_strip->count())
849 new_index = target_tab_strip->count(); 852 new_index = target_tab_strip->count();
850 853
851 target_tab_strip->InsertTabContentsAt(new_index, contents, 854 target_tab_strip->InsertTabContentsAt(new_index, contents,
852 TabStripModel::ADD_NONE); 855 TabStripModel::ADD_NONE);
853 856
854 if (has_callback()) 857 if (has_callback())
855 result_.reset(ExtensionTabUtil::CreateTabValue(contents, 858 result_.reset(ExtensionTabUtil::CreateTabValue(contents->tab_contents(),
856 target_tab_strip, new_index)); 859 target_tab_strip, new_index));
857 860
858 return true; 861 return true;
859 } 862 }
860 } 863 }
861 864
862 // Perform a simple within-window move. 865 // Perform a simple within-window move.
863 // Clamp move location to the last position. 866 // Clamp move location to the last position.
864 // This is ">=" because the move must be to an existing location. 867 // This is ">=" because the move must be to an existing location.
865 if (new_index >= source_tab_strip->count()) 868 if (new_index >= source_tab_strip->count())
866 new_index = source_tab_strip->count() - 1; 869 new_index = source_tab_strip->count() - 1;
867 870
868 if (new_index != tab_index) 871 if (new_index != tab_index)
869 source_tab_strip->MoveTabContentsAt(tab_index, new_index, false); 872 source_tab_strip->MoveTabContentsAt(tab_index, new_index, false);
870 873
871 if (has_callback()) 874 if (has_callback())
872 result_.reset(ExtensionTabUtil::CreateTabValue(contents, source_tab_strip, 875 result_.reset(ExtensionTabUtil::CreateTabValue(contents->tab_contents(),
876 source_tab_strip,
873 new_index)); 877 new_index));
874 return true; 878 return true;
875 } 879 }
876 880
877 881
878 bool RemoveTabFunction::RunImpl() { 882 bool RemoveTabFunction::RunImpl() {
879 int tab_id; 883 int tab_id;
880 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); 884 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id));
881 885
882 Browser* browser = NULL; 886 Browser* browser = NULL;
883 TabContents* contents = NULL; 887 TabContentsWrapper* contents = NULL;
884 if (!GetTabById(tab_id, profile(), include_incognito(), 888 if (!GetTabById(tab_id, profile(), include_incognito(),
885 &browser, NULL, &contents, NULL, &error_)) 889 &browser, NULL, &contents, NULL, &error_))
886 return false; 890 return false;
887 891
888 // Close the tab in this convoluted way, since there's a chance that the tab 892 // Close the tab in this convoluted way, since there's a chance that the tab
889 // is being dragged, or we're in some other nested event loop. This code path 893 // is being dragged, or we're in some other nested event loop. This code path
890 // should ensure that the tab is safely closed under such circumstances, 894 // should ensure that the tab is safely closed under such circumstances,
891 // whereas |Browser::CloseTabContents()| does not. 895 // whereas |Browser::CloseTabContents()| does not.
892 RenderViewHost* render_view_host = contents->render_view_host(); 896 RenderViewHost* render_view_host = contents->render_view_host();
893 render_view_host->delegate()->Close(render_view_host); 897 render_view_host->delegate()->Close(render_view_host);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1052 base::Base64Encode(stream_as_string, &base64_result); 1056 base::Base64Encode(stream_as_string, &base64_result);
1053 base64_result.insert(0, base::StringPrintf("data:%s;base64,", 1057 base64_result.insert(0, base::StringPrintf("data:%s;base64,",
1054 mime_type.c_str())); 1058 mime_type.c_str()));
1055 result_.reset(new StringValue(base64_result)); 1059 result_.reset(new StringValue(base64_result));
1056 SendResponse(true); 1060 SendResponse(true);
1057 } 1061 }
1058 1062
1059 bool DetectTabLanguageFunction::RunImpl() { 1063 bool DetectTabLanguageFunction::RunImpl() {
1060 int tab_id = 0; 1064 int tab_id = 0;
1061 Browser* browser = NULL; 1065 Browser* browser = NULL;
1062 TabContents* contents = NULL; 1066 TabContentsWrapper* contents = NULL;
1063 1067
1064 // If |tab_id| is specified, look for it. Otherwise default to selected tab 1068 // If |tab_id| is specified, look for it. Otherwise default to selected tab
1065 // in the current window. 1069 // in the current window.
1066 if (HasOptionalArgument(0)) { 1070 if (HasOptionalArgument(0)) {
1067 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); 1071 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id));
1068 if (!GetTabById(tab_id, profile(), include_incognito(), 1072 if (!GetTabById(tab_id, profile(), include_incognito(),
1069 &browser, NULL, &contents, NULL, &error_)) { 1073 &browser, NULL, &contents, NULL, &error_)) {
1070 return false; 1074 return false;
1071 } 1075 }
1072 if (!browser || !contents) 1076 if (!browser || !contents)
1073 return false; 1077 return false;
1074 } else { 1078 } else {
1075 browser = GetCurrentBrowser(); 1079 browser = GetCurrentBrowser();
1076 if (!browser) 1080 if (!browser)
1077 return false; 1081 return false;
1078 contents = browser->tabstrip_model()->GetSelectedTabContents(); 1082 contents = browser->tabstrip_model()->GetSelectedTabContents();
1079 if (!contents) 1083 if (!contents)
1080 return false; 1084 return false;
1081 } 1085 }
1082 1086
1083 if (contents->controller().needs_reload()) { 1087 if (contents->controller().needs_reload()) {
1084 // If the tab hasn't been loaded, don't wait for the tab to load. 1088 // If the tab hasn't been loaded, don't wait for the tab to load.
1085 error_ = keys::kCannotDetermineLanguageOfUnloadedTab; 1089 error_ = keys::kCannotDetermineLanguageOfUnloadedTab;
1086 return false; 1090 return false;
1087 } 1091 }
1088 1092
1089 AddRef(); // Balanced in GotLanguage() 1093 AddRef(); // Balanced in GotLanguage()
1090 1094
1091 if (!contents->language_state().original_language().empty()) { 1095 if (!contents->tab_contents()->language_state().original_language().empty()) {
1092 // Delay the callback invocation until after the current JS call has 1096 // Delay the callback invocation until after the current JS call has
1093 // returned. 1097 // returned.
1094 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( 1098 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
1095 this, &DetectTabLanguageFunction::GotLanguage, 1099 this, &DetectTabLanguageFunction::GotLanguage,
1096 contents->language_state().original_language())); 1100 contents->tab_contents()->language_state().original_language()));
1097 return true; 1101 return true;
1098 } 1102 }
1099 // The tab contents does not know its language yet. Let's wait until it 1103 // The tab contents does not know its language yet. Let's wait until it
1100 // receives it, or until the tab is closed/navigates to some other page. 1104 // receives it, or until the tab is closed/navigates to some other page.
1101 registrar_.Add(this, NotificationType::TAB_LANGUAGE_DETERMINED, 1105 registrar_.Add(this, NotificationType::TAB_LANGUAGE_DETERMINED,
1102 Source<TabContents>(contents)); 1106 Source<TabContents>(contents->tab_contents()));
1103 registrar_.Add(this, NotificationType::TAB_CLOSING, 1107 registrar_.Add(this, NotificationType::TAB_CLOSING,
1104 Source<NavigationController>(&(contents->controller()))); 1108 Source<NavigationController>(&(contents->controller())));
1105 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, 1109 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
1106 Source<NavigationController>(&(contents->controller()))); 1110 Source<NavigationController>(&(contents->controller())));
1107 return true; 1111 return true;
1108 } 1112 }
1109 1113
1110 void DetectTabLanguageFunction::Observe(NotificationType type, 1114 void DetectTabLanguageFunction::Observe(NotificationType type,
1111 const NotificationSource& source, 1115 const NotificationSource& source,
1112 const NotificationDetails& details) { 1116 const NotificationDetails& details) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 *error_message = ExtensionErrorUtils::FormatErrorMessage( 1153 *error_message = ExtensionErrorUtils::FormatErrorMessage(
1150 keys::kWindowNotFoundError, base::IntToString(window_id)); 1154 keys::kWindowNotFoundError, base::IntToString(window_id));
1151 1155
1152 return NULL; 1156 return NULL;
1153 } 1157 }
1154 1158
1155 static bool GetTabById(int tab_id, Profile* profile, 1159 static bool GetTabById(int tab_id, Profile* profile,
1156 bool include_incognito, 1160 bool include_incognito,
1157 Browser** browser, 1161 Browser** browser,
1158 TabStripModel** tab_strip, 1162 TabStripModel** tab_strip,
1159 TabContents** contents, 1163 TabContentsWrapper** contents,
1160 int* tab_index, 1164 int* tab_index,
1161 std::string* error_message) { 1165 std::string* error_message) {
1162 if (ExtensionTabUtil::GetTabById(tab_id, profile, include_incognito, 1166 if (ExtensionTabUtil::GetTabById(tab_id, profile, include_incognito,
1163 browser, tab_strip, contents, tab_index)) 1167 browser, tab_strip, contents, tab_index))
1164 return true; 1168 return true;
1165 1169
1166 if (error_message) 1170 if (error_message)
1167 *error_message = ExtensionErrorUtils::FormatErrorMessage( 1171 *error_message = ExtensionErrorUtils::FormatErrorMessage(
1168 keys::kTabNotFoundError, base::IntToString(tab_id)); 1172 keys::kTabNotFoundError, base::IntToString(tab_id));
1169 1173
(...skipping 12 matching lines...) Expand all
1182 } 1186 }
1183 1187
1184 static GURL ResolvePossiblyRelativeURL(std::string url_string, 1188 static GURL ResolvePossiblyRelativeURL(std::string url_string,
1185 const Extension* extension) { 1189 const Extension* extension) {
1186 GURL url = GURL(url_string); 1190 GURL url = GURL(url_string);
1187 if (!url.is_valid()) 1191 if (!url.is_valid())
1188 url = extension->GetResourceURL(url_string); 1192 url = extension->GetResourceURL(url_string);
1189 1193
1190 return url; 1194 return url;
1191 } 1195 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698