1 /*
   2  * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include "config.h"
  27 #include "InspectorClientJava.h"
  28 
  29 #include "Frame.h"
  30 #include "NotImplemented.h"
  31 #include "Page.h"
  32 #include "RenderObject.h"
  33 #include "WebPage.h"
  34 
  35 namespace InspectorClientJavaInternal {
  36 
  37 static JGClass webPageClass;
  38 static jmethodID repaintAllMethod;
  39 static jmethodID sendInspectorMessageToFrontendMethod;
  40 
  41 static void initRefs(JNIEnv* env)
  42 {
  43     if (!webPageClass) {
  44         webPageClass = JLClass(env->FindClass(
  45                 "com/sun/webkit/WebPage"));
  46         ASSERT(webPageClass);
  47 
  48         repaintAllMethod = env->GetMethodID(
  49                 webPageClass,
  50                 "fwkRepaintAll",
  51                 "()V");
  52         ASSERT(repaintAllMethod);
  53 
  54         sendInspectorMessageToFrontendMethod = env->GetMethodID(
  55                 webPageClass,
  56                 "fwkSendInspectorMessageToFrontend",
  57                 "(Ljava/lang/String;)Z");
  58         ASSERT(sendInspectorMessageToFrontendMethod);
  59     }
  60 }
  61 }
  62 
  63 namespace WebCore {
  64 
  65 InspectorClientJava::InspectorClientJava(const JLObject &webPage)
  66     : m_webPage(webPage)
  67 {
  68 }
  69 
  70 void InspectorClientJava::inspectedPageDestroyed()
  71 {
  72     delete this;
  73 }
  74 
  75 Inspector::FrontendChannel* InspectorClientJava::openLocalFrontend(InspectorController*)
  76 {
  77     //FIXME: need to be realized!
  78     notImplemented();
  79     return this;
  80 }
  81 
  82 void InspectorClientJava::bringFrontendToFront()
  83 {
  84     notImplemented();
  85 }
  86 
  87 void InspectorClientJava::highlight()
  88 {
  89     using namespace InspectorClientJavaInternal;
  90     // InspectorController::drawHighlight() may want to draw outside any
  91     // node boundary so our only option here is invalidate the entire page.
  92     // See also WebPage_twkDrawHighlight.
  93 
  94     JNIEnv* env = WebCore_GetJavaEnv();
  95     initRefs(env);
  96 
  97     env->CallVoidMethod(m_webPage, repaintAllMethod);
  98     CheckAndClearException(env);
  99 }
 100 
 101 void InspectorClientJava::hideHighlight()
 102 {
 103     highlight();
 104 }
 105 
 106 void InspectorClientJava::sendMessageToFrontend(const String& message)
 107 {
 108     using namespace InspectorClientJavaInternal;
 109     JNIEnv* env = WebCore_GetJavaEnv();
 110     initRefs(env);
 111 
 112     env->CallBooleanMethod(m_webPage,
 113                            sendInspectorMessageToFrontendMethod,
 114                            (jstring)message.toJavaString(env));
 115     CheckAndClearException(env);
 116 }
 117 
 118 } // namespace WebCore