Index: chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/contextualsearch/ContextualSearchPanel.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/contextualsearch/ContextualSearchPanel.java b/chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/contextualsearch/ContextualSearchPanel.java |
index ff37a872fd28a07d09946f74a921e0d420733cd7..6c5425bde1c19358b865c27bb897d4dea7f7e487 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/contextualsearch/ContextualSearchPanel.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/compositor/bottombar/contextualsearch/ContextualSearchPanel.java |
@@ -22,7 +22,7 @@ import org.chromium.content.browser.ContentViewCore; |
* Controls the Contextual Search Panel. |
*/ |
public class ContextualSearchPanel extends ContextualSearchPanelAnimation |
- implements ContextualSearchPanelDelegate { |
+ implements ContextualSearchPanelDelegate, OverlayPanelContentFactory { |
/** |
* State of the Contextual Search Panel. |
@@ -108,6 +108,11 @@ public class ContextualSearchPanel extends ContextualSearchPanelAnimation |
private ContextualSearchPanelHost mSearchPanelHost; |
/** |
+ * That factory that creates OverlayPanelContents. |
+ */ |
+ private OverlayPanelContentFactory mContentFactory; |
+ |
+ /** |
* Container for content the panel will show. |
*/ |
private OverlayPanelContent mOverlayPanelContent; |
@@ -115,7 +120,7 @@ public class ContextualSearchPanel extends ContextualSearchPanelAnimation |
/** |
* Used for logging state changes. |
*/ |
- private ContextualSearchPanelMetrics mPanelMetrics; |
+ private final ContextualSearchPanelMetrics mPanelMetrics; |
/** |
* The object for handling global Contextual Search management duties |
@@ -132,12 +137,21 @@ public class ContextualSearchPanel extends ContextualSearchPanelAnimation |
*/ |
public ContextualSearchPanel(Context context, LayoutUpdateHost updateHost) { |
super(context, updateHost); |
+ mContentFactory = this; |
mPanelMetrics = new ContextualSearchPanelMetrics(); |
} |
/** |
- * Create a new OverlayPanelContent object. This can be overridden for tests. |
+ * Destroy the panel's components. |
*/ |
+ public void destroy() { |
+ destroyOverlayPanelContent(); |
+ destroyPromoView(); |
+ destroyPeekPromoControl(); |
+ destroySearchBarControl(); |
+ } |
+ |
+ @Override |
public OverlayPanelContent createNewOverlayPanelContent() { |
OverlayPanelContent overlayPanelContent = new OverlayPanelContent( |
mManagementDelegate.getOverlayContentDelegate(), new PanelProgressObserver(), |
@@ -287,12 +301,8 @@ public class ContextualSearchPanel extends ContextualSearchPanelAnimation |
} |
@Override |
- protected void onClose(StateChangeReason reason) { |
- destroySearchBarControl(); |
- destroyPeekPromoControl(); |
- if (mOverlayPanelContent != null) { |
- mOverlayPanelContent.destroyContentView(); |
- } |
+ protected void onClosed(StateChangeReason reason) { |
+ destroy(); |
mManagementDelegate.onCloseContextualSearch(reason); |
} |
@@ -517,14 +527,24 @@ public class ContextualSearchPanel extends ContextualSearchPanelAnimation |
/** |
* @return A new OverlayPanelContent if the instance was null or the existing one. |
*/ |
- public OverlayPanelContent getOverlayPanelContent() { |
+ protected OverlayPanelContent getOverlayPanelContent() { |
// Only create the content when necessary |
if (mOverlayPanelContent == null) { |
- mOverlayPanelContent = createNewOverlayPanelContent(); |
+ mOverlayPanelContent = mContentFactory.createNewOverlayPanelContent(); |
} |
return mOverlayPanelContent; |
} |
+ /** |
+ * Destroys the OverlayPanelContent. |
+ */ |
+ protected void destroyOverlayPanelContent() { |
+ if (mOverlayPanelContent != null) { |
+ mOverlayPanelContent.destroy(); |
+ mOverlayPanelContent = null; |
+ } |
+ } |
+ |
// ============================================================================================ |
// ContextualSearchPanelBase methods. |
// ============================================================================================ |
@@ -953,23 +973,13 @@ public class ContextualSearchPanel extends ContextualSearchPanelAnimation |
} |
@Override |
- public void setSearchContentViewVisibility(boolean isVisible) { |
- getOverlayPanelContent().setVisibility(isVisible); |
- } |
- |
- /** |
- * Destroy the native components associated with this panel's content. |
- */ |
- public void destroy() { |
- // It is possible that an OverlayPanelContent was never created for this panel. |
- if (mOverlayPanelContent != null) { |
- mOverlayPanelContent.destroy(); |
- } |
+ public void acknowledgeIntentToLoad() { |
+ getOverlayPanelContent().acknowledgeIntentToShowContent(); |
} |
@Override |
@VisibleForTesting |
- public void setOverlayPanelContent(OverlayPanelContent panelContent) { |
- mOverlayPanelContent = panelContent; |
+ public void setOverlayPanelContentFactory(OverlayPanelContentFactory factory) { |
+ mContentFactory = factory; |
} |
} |