OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser.browseractions; |
| 6 |
| 7 import android.content.Context; |
| 8 |
| 9 import org.chromium.base.ContextUtils; |
| 10 import org.chromium.chrome.browser.TabState; |
| 11 import org.chromium.chrome.browser.tab.Tab; |
| 12 import org.chromium.chrome.browser.tab.TabDelegateFactory; |
| 13 import org.chromium.chrome.browser.tabmodel.TabCreatorManager; |
| 14 import org.chromium.chrome.browser.tabmodel.TabModel; |
| 15 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; |
| 16 import org.chromium.content_public.browser.LoadUrlParams; |
| 17 import org.chromium.content_public.browser.WebContents; |
| 18 import org.chromium.ui.base.WindowAndroid; |
| 19 |
| 20 /** |
| 21 * The manager returns a {@link BrowserActionsTabCreator} to create Tabs for Bro
wser Actions. |
| 22 */ |
| 23 public class BrowserActionsTabCreatorManager implements TabCreatorManager { |
| 24 private final BrowserActionsTabCreator mTabCreator; |
| 25 |
| 26 public BrowserActionsTabCreatorManager() { |
| 27 mTabCreator = new BrowserActionsTabCreator(); |
| 28 } |
| 29 |
| 30 /** |
| 31 * This class creates various kinds of new tabs specific for Browser Actions
. |
| 32 * The created tabs are not bound with {@link ChromeActivity}. |
| 33 */ |
| 34 public class BrowserActionsTabCreator extends TabCreator { |
| 35 private TabModel mTabModel; |
| 36 |
| 37 @Override |
| 38 public boolean createsTabsAsynchronously() { |
| 39 return true; |
| 40 } |
| 41 |
| 42 @Override |
| 43 public Tab createNewTab(LoadUrlParams loadUrlParams, TabLaunchType type,
Tab parent) { |
| 44 Context context = ContextUtils.getApplicationContext(); |
| 45 WindowAndroid windowAndroid = new WindowAndroid(context); |
| 46 Tab tab = Tab.createTabForLazyLoad( |
| 47 false, windowAndroid, type, Tab.INVALID_TAB_ID, loadUrlParam
s); |
| 48 tab.initialize(null, null, new TabDelegateFactory(), true, false); |
| 49 mTabModel.addTab(tab, -1, TabLaunchType.FROM_BROWSER_ACTIONS); |
| 50 return tab; |
| 51 } |
| 52 |
| 53 @Override |
| 54 public Tab createFrozenTab(TabState state, int id, int index) { |
| 55 Tab tab = Tab.createFrozenTabFromState(id, false, null, Tab.INVALID_
TAB_ID, state); |
| 56 mTabModel.addTab(tab, index, TabLaunchType.FROM_RESTORE); |
| 57 return tab; |
| 58 } |
| 59 |
| 60 @Override |
| 61 public Tab launchUrl(String url, TabLaunchType type) { |
| 62 return createNewTab(new LoadUrlParams(url), type, null); |
| 63 } |
| 64 |
| 65 @Override |
| 66 public boolean createTabWithWebContents( |
| 67 Tab parent, WebContents webContents, int parentId, TabLaunchType
type, String url) { |
| 68 createNewTab(new LoadUrlParams(url), type, null); |
| 69 return true; |
| 70 } |
| 71 |
| 72 /** |
| 73 * Sets the tab model and tab content manager to use. |
| 74 * @param model The new {@link TabModel} to use. |
| 75 */ |
| 76 public void setTabModel(TabModel model) { |
| 77 mTabModel = model; |
| 78 } |
| 79 } |
| 80 |
| 81 @Override |
| 82 public TabCreator getTabCreator(boolean incognito) { |
| 83 return mTabCreator; |
| 84 } |
| 85 } |
OLD | NEW |