11320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// Copyright 2014 The Chromium Authors. All rights reserved.
21320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// Use of this source code is governed by a BSD-style license that can be
31320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// found in the LICENSE file.
41320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
51320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#ifndef CHROMECAST_SHELL_BROWSER_ANDROID_CAST_WINDOW_ANDROID_H_
61320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#define CHROMECAST_SHELL_BROWSER_ANDROID_CAST_WINDOW_ANDROID_H_
71320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
81320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include <jni.h>
91320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include <vector>
101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/android/jni_string.h"
121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/android/scoped_java_ref.h"
131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/basictypes.h"
141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/callback_forward.h"
151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/command_line.h"
161320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/macros.h"
171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/memory/scoped_ptr.h"
181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/memory/weak_ptr.h"
191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "build/build_config.h"
201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "content/public/browser/web_contents.h"
211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "content/public/browser/web_contents_delegate.h"
221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "content/public/browser/web_contents_observer.h"
231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "content/public/common/content_switches.h"
241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "ui/gfx/native_widget_types.h"
251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "ui/gfx/size.h"
261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass GURL;
281320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccinamespace content {
301320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass BrowserContext;
311320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass SiteInstance;
321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass WebContents;
331320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}  // namespace content
341320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
351320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccinamespace chromecast {
361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccinamespace shell {
371320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass CastWindowAndroid : public content::WebContentsDelegate,
391320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                          public content::WebContentsObserver {
401320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci public:
411320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Creates a new window and immediately loads the given URL.
421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  static CastWindowAndroid* CreateNewWindow(
431320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      content::BrowserContext* browser_context,
441320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      const GURL& url);
451320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
461320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual ~CastWindowAndroid();
471320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
481320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void LoadURL(const GURL& url);
491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Calls RVH::ClosePage() and waits for acknowledgement before closing/
501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // deleting the window.
511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void Close();
521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Destroys this window immediately.
531320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  void Destroy();
541320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Registers the JNI methods for CastWindowAndroid.
561320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  static bool RegisterJni(JNIEnv* env);
571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
581320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // content::WebContentsDelegate implementation:
591320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void AddNewContents(content::WebContents* source,
601320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                              content::WebContents* new_contents,
611320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                              WindowOpenDisposition disposition,
621320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                              const gfx::Rect& initial_pos,
631320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                              bool user_gesture,
641320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                              bool* was_blocked) OVERRIDE;
651320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void CloseContents(content::WebContents* source) OVERRIDE;
661320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual bool CanOverscrollContent() const OVERRIDE;
671320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual bool AddMessageToConsole(content::WebContents* source,
681320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                   int32 level,
691320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                   const base::string16& message,
701320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                   int32 line_no,
711320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                                   const base::string16& source_id) OVERRIDE;
721320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void ActivateContents(content::WebContents* contents) OVERRIDE;
731320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void DeactivateContents(content::WebContents* contents) OVERRIDE;
741320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
751320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // content::WebContentsObserver implementation:
761320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
771320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
781320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci private:
791320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  explicit CastWindowAndroid(content::WebContents* web_contents);
801320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
811320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Helper to create a new CastWindowAndroid given a newly created WebContents.
821320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  static CastWindowAndroid* CreateCastWindowAndroid(
831320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      content::WebContents* web_contents,
841320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      const gfx::Size& initial_size);
851320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
861320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  base::android::ScopedJavaGlobalRef<jobject> java_object_;
871320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  scoped_ptr<content::WebContents> web_contents_;
881320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
891320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  base::WeakPtrFactory<CastWindowAndroid> weak_factory_;
901320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
911320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  DISALLOW_COPY_AND_ASSIGN(CastWindowAndroid);
921320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci};
931320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
941320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}  // namespace shell
951320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}  // namespace chromecast
961320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
971320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#endif  // CHROMECAST_SHELL_BROWSER_ANDROID_CAST_WINDOW_ANDROID_H_
98